ssh配置问题

配置spring3+hibernate4,报错如下:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dragService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'dragInfoImpl' must be of type [com.edu.whu.sc.entity.DraginfoImpl], but was actually of type [$Proxy17]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3954)
	at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426)
	at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'dragInfoImpl' must be of type [com.edu.whu.sc.entity.DraginfoImpl], but was actually of type [$Proxy17]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:361)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:550)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:159)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)
	... 24 more



Dao文件如下:
package com.edu.whu.sc.entityDao;

import java.util.List;

import com.edu.whu.sc.entity.Draginfo;

public interface DraginfoDao {
	void save(Draginfo draginfo);
	List<Draginfo> findSimilarByName(String name);
}

Dao文件实现如下:

package com.edu.whu.sc.entity;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;

import com.edu.whu.sc.entityDao.DraginfoDao;
@Component("dragInfoImpl")
public class DraginfoImpl implements DraginfoDao{
	
	private SessionFactory sessionFactory;
	public DraginfoImpl() {
		// TODO Auto-generated constructor stub
	}

	public void save(Draginfo draginfo){
		Session session = sessionFactory.getCurrentSession();
//		session.getTransaction().begin();
		session.save(draginfo);
//		session.getTransaction().commit();
	}
	
	public List<Draginfo> findSimilarByName(String name){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from draginfo di where di.name like '%:name%'").setString("name", name);
		List<Draginfo> resultList = query.list();
		
		return resultList;
	}
	
	public SessionFactory getSessionFactory(){
		return this.sessionFactory;
	}
	
	@Resource(name = "sessionFactory")
	public void setSessionFactory (SessionFactory sessionFactory){
		this.sessionFactory = sessionFactory;
	}
}



service文件如下:

package com.edu.whu.sc.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.edu.whu.sc.daoimpl.DraginfoImpl;
import com.edu.whu.sc.entity.Draginfo;
import com.edu.whu.sc.entityDao.DraginfoDao;
import com.edu.whu.sc.serviceDao.DraginfoServiceDao;
@Component("dragService")
public class DragService implements DraginfoServiceDao{

	private DraginfoDao draginfoImpl;
	public DragService() {
		// TODO Auto-generated constructor stub
	}
	public DraginfoDao getDraginfoImpl() {
		return draginfoImpl;
	}
	
	@Resource(name="dragInfoImpl")
	public void setDraginfoImpl(DraginfoImpl draginfoImpl) {
		//此处改为DraginfoDao
		this.draginfoImpl = draginfoImpl;
	}
	
	public List<Draginfo> findSimilarByName(String name) {
		return draginfoImpl.findSimilarByName(name);
	}
	
}











你可能感兴趣的:(ssh配置,dao接口)