报错'sessionFactory' or 'hibernateTemplate' is required,但是spring里已经配置注入

部分错误提示

            java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:118)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
... 42 more

spring整个配置文件

<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
    <property name="jdbcUrl" value="jdbc:mysql:///news2?characterEncoding=utf-8"></property>
    <property name="user" value="root"></property>
    <property name="password" value="1234"></property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocations" value="classpath:hibernate.cfg.xml"></property>
    <property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 事务管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 事务管理驱动 -->
<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="catalogDAO" class="com.lfy.dao.impl.CatalogDAOImpl">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="articleDAO" class="com.lfy.dao.impl.ArticleDAOImpl">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="catalogService" class="com.lfy.service.impl.CatalogServiceImpl">
    <property name="catalogDAO" ref="catalogDAO" />
</bean>

<bean id="articleService" class="com.lfy.service.impl.ArticleServiceImpl">
    <property name="articleDAO" ref="articleDAO" />
</bean>

<bean id="catalogAction" class="com.lfy.action.CatalogAction" scope="prototype">
    <property name="catalogService" ref="catalogService" />
</bean>

<bean id="articleAction" class="com.lfy.action.ArticleAction" scope="prototype">
    <property name="articleService" ref="articleService" />
</bean>

<bean id="indexAction" class="com.lfy.action.IndexAction" scope="prototype">
    <property name="catalogService" ref="catalogService" />
</bean>

DAO实现类
public class ArticleDAOImpl extends HibernateDaoSupport implements ArticleDAO {

public List<Article> findall() {
    String hql="from Article";
    List<Article> articles=this.getHibernateTemplate().find(hql);
    return articles;
}

}

配置hibernate mapping的时候没有问题,可以自动建表,一加上DAO操作就会报
java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
不知道是哪里错误,用了能够成功的项目的spring配置文件也会报同样错误,没有C币了可以帮忙看一看吗?

qq_16127313
爱码少年 CatalogDAOImpl 放出来看看
11 个月之前 回复

2个回答

看HibernateDaoSupport 代码,需要注入 hibernateTemplate 或者 sessionFactory
图片说明

需要在dao里面加入

@Autowired
HibernateTemplate hibernateTemplate;

或者

@Autowired
private SessionFactory sessionFactory;

    回答完毕!
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
spring3报错'sessionFactory' or 'hibernateTemplate' is required
rn整合spring3和hibernate3.6rnspring配置:(不用对DAO进行配置)rn rn //[color=#FF0000]是这行配置为扫描,所以不用对dao进行配置吗?[/color]rn rn rn rnrn原先的代码:([color=#FF0000]运行正确[/color])rnBaseDao:rnpublic class BaseDao rn protected HibernateTemplate hibernateTemplate;rn public HibernateTemplate getHibernateTemplate() rn return hibernateTemplate;rn rn @Resourcern public void setHibernateTemplate(HibernateTemplate hibernateTemplate) rn this.hibernateTemplate = hibernateTemplate;rn rnrnExpertDao:rn@Component("expertDao")//[color=#FF0000]这行什么意思?[/color]rnpublic class ExpertDao extends BaseDao rn //用hibernateTemplate实现的增删改操作。。。rnrn=================================上面这样是运行正常的,后来改了代码:rnBaseDao:rnpublic class BaseDao extends HibernateDaoSupport rn public List findAll(String object) rn return this.getHibernateTemplate().find("from " + object);rn rn 。。。。。。rnrnExpertDao:rn@Component("expertDao")rnpublic class ExpertDao extends BaseDao rn public List findAll() rn return super.findAll(objname);rn rnrn=================================这样改了就提示错误:rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'expertDao' defined in file [E:\Project\WebRoot\WEB-INF\classes\com\ExpertDao.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrnrnrn
异常 'sessionFactory' or 'hibernateTemplate' is required
[b]struts2 xml配置如下:[/b] rn rn /brandManager.jsprn /error.jsprn rnspring xml 配置如下:rnrn rnrnrnrn rnrnrnrn rnrnsessionFactory datasource配置省略rnrnrnrn服务器启动报这个异常 'sessionFactory' or 'hibernateTemplate' is requiredrn不能创建Beanrn郁闷啊!!帮我分析下哪些地方有可能出问题??
ssh('sessionFactory' or 'hibernateTemplate' is required)
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:554)rn at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:164)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:92)rn at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)rn ... 41 morernCaused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:118)rn at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)rn ... 53 morern2013-3-13 22:19:14 org.apache.catalina.core.StandardContext startrn严重: Error listenerStartrn2013-3-13 22:19:14 org.apache.catalina.core.StandardContext startrn严重: Context [/test_ano] startup failed due to previous errorsrn2013-3-13 22:19:14 org.apache.catalina.core.ApplicationContext logrn信息: Closing Spring root WebApplicationContextrn2013-3-13 22:19:14 org.apache.coyote.http11.Http11Protocol startrn信息: Starting Coyote HTTP/1.1 on http-8080rn2013-3-13 22:19:14 org.apache.jk.common.ChannelSocket initrn信息: JK: ajp13 listening on /0.0.0.0:8009rn2013-3-13 22:19:14 org.apache.jk.server.JkMain startrn信息: Jk running ID=0 time=0/20 config=nullrn2013-3-13 22:19:14 org.apache.catalina.startup.Catalina startrn信息: Server startup in 1888 msrnrnspring.xmlrnrnrnrn rn rn classpath:jdbc.propertiesrn rn rn rn rn rnrn rn rn rn rn rn rnrn rn rn rn rn org.ssh.anotation.modelrn rn rn rn rn rn org.hibernate.dialect.MySQL5Dialectrn truern creatern truern rn rn rn rn rn rn rnrn rn rn rnrnrn rn rn rn rnrnrn rn rn rn rn rn rn
'sessionFactory' or 'hibernateTemplate' is required
用注解自动注入可以成功代码rn[code=java]rnpublic class CommonDaoImpl extends HibernateDaoSupport implements ICommonDao rnrn public void save(T t) rn this.getHibernateTemplate().save(t);rn rn// @Resource(name="sessionFactory")rn// public final void setSessionFactoryMe(SessionFactory sessionFactory)rn// super.setSessionFactory(sessionFactory);rn// rnrnrn[/code]rnrn如果用beans.xml注入会报错:注入代码rn[code=java] rn rn [/code]rnrn完整报错是:rn[code=java]rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.jin.elec.dao.impl.ElecTextDaoImpl' defined in file [D:\Workspaces\jinelel2\WebRoot\WEB-INF\classes\cn\jin\elec\dao\impl\ElecTextDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1337)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)rn at junit.TestDao.saveElecText(TestDao.java:18)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:592)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)rn at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)rn at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:236)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:117)rn at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)rn ... 38 morernrn[/code]rn
ssh整合时报sessionFactory or hibernateTemplate is required
rnsessionFactory明明已经加进来了,怎么还报sessionFactory or hibernateTemplate is required,高手帮忙一下rn rn rn rn rnrn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rnrnrn rn rn rn rn rn rn rn rn rn rn rn rn
Spring 使用注解配置事物时出现:'sessionFactory' or 'hibernateTemplate' is required
spring 配置文件如下:rn[code=XML]rnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn[/code]rnrnPersonDaoImpl 代码声明(加了注释)如下:rn[code=Java]rn@Transactionalrn@Component("personDao")rnpublic class PersonDaoImpl extends HibernateDaoSupport implements PersonDao...rn[/code]rnrn客户端代码如下:rn[code=Java]rn BeanFactory beanFactory = new ClassPathXmlApplicationContext("applicationContext.xml");rn rn PersonDao personDao = (PersonDao)beanFactory.getBean("personDao");rn rn Person person = new Person("Unmi",23,"OK,Fu");rn rn personDao.save(person);rn[/code]rnrn执行后出现异常:rn2010-04-15 13:35:43,765 [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[INFO] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@667cbde6: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,personDao,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,sessionFactory,transactionManager]; root of factory hierarchyrn[color=#FF0000]Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDao' defined in file [E:\workspace\TestSpring\bin\com\unmi\dao\impl\PersonDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1403)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)rn at com.unmi.test.Client.main(Client.java:15)rnCaused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:118)rn at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)rn ... 12 more[/color]rn请问一下,该如何解决啊,怎么才能把 SessionFactory 或 HibernateTemplate 设置给 PersonDaoImpl 呢?
java.lang.IllegalArgumentException: Property 'sessionFactory' is required 报错
用spring+Hibernate试着写一个testrn一直报 java.lang.IllegalArgumentException: Property 'sessionFactory' is requiredrn调试着感觉是dao的问题 可是在applicationContext中dao已经配置了sessionFactory 不知道到底是哪里出了问题 rn代码如下 rnapplicationContext.xml[code=java]rn rn rn rn rn rn rn rn com.org.entity.Register.hbm.xmlrn com/org/entity/Photo.hbm.xmlrn rn rn rn rn rn hibernate.dialect=org.hibernate.dialect.MySQLDialectrn hibernate.hbm2ddl.auto=updatern hibernate.show_sql=truern hibernate.formate_sql=falsern rn rn rnrn rn rn rn rn[/code]rnrn然后是PhotoDaoImpl.javarn[code=java]package com.org.dao.impl;rnrnimport com.org.dao.PhotoDao;rnimport com.org.entity.Photo;rnrnrnimport org.hibernate.SessionFactory;rnimport org.springframework.orm.hibernate3.HibernateTemplate;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnrnpublic class PhotoDaoImpl implements PhotoDaorn rn private HibernateTemplate hibernateTemplate ;rn rn private SessionFactory sessionFactory; rn rn rn rn //设值注入SessionFactory必需的setter方法rn rn public void setSessionFactory(SessionFactory sessionFactory)rnrn rnrn this.sessionFactory = sessionFactory;rn System.out.print("sessionFactory is injected");rnrn rn rn public SessionFactory getSessionFactory()rn return this.sessionFactory;rn rn rn public HibernateTemplate getHibernateTemplate()rn if ( hibernateTemplate == null)rnrn rnrn //如果不存在,新建一个HibernateTemplate实例rnrn hibernateTemplate = new HibernateTemplate(sessionFactory);rnrn rnrn return hibernateTemplate; rn rn rn rn public void addPhoto(Photo photo)throws Exceptionrn getHibernateTemplate().saveOrUpdate(photo);rn System.out.print(photo.getPhotoname()+"is saving");rn rnrnrn[/code]rnrn看网上的大部分问题都是service没有设sessionFactory的依赖rn我这个直接绕过service了 在servlet里直接是new一个photoDaoImpl来用 rn根据那几个print 应该是创建photoDaoImpl的时候出了问题 rn还是不知道问题在哪 rn拜托高手解答
关于Spring hibernateTemplate注入?
RT:n 问题描述:每个数据访问层都对hibernateTemplate进行了注入,现想可不可以拦截DAO层,通过配置给每个层的hibernateTemplate进行注入?具体的实例更好
一个模拟Spring将SessionFactory注入到HibernateTemplate的小例子
NULL 博文链接:https://tedtian.iteye.com/blog/1988917
注解方式配置SessionFactory的注入
之前程序中的SessionFactory都是通过hibernate的方式获取的: Configuration().configure("hibernate.cfg.xml").buildSessionFactory(); 因为一些问题想要改成Spring注入的方式,但是我的程序都是使用的注解的方式注入bean,为了保持一致性还是用@Bean来配置SessionFactory 首先
sessionfactory注入报错 ,跪求高手
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.hibernate.impl.SessionFactoryImpl' to required type 'org.hibernate.SessionFactory' for property 'sessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.hibernate.SessionFactory] for property 'sessionFactory': no matching editors or conversion strategy foundrnapplicationContet.xmlrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn org/crazyit/app/domain/Person.hbm.xmlrn rn rn rn rn rn rn hibernate.dialect=org.hibernate.dialect.OracleDialectrn hibernate.hbm2ddl.auto=updatern hibernate.show_sql=truern hibernate.format_sql=true;rn rn rn rn rn rnrn rn rn rn rn rn rn rnrnrnWeb.xmlrnrnrn rn rn index.jsprn rn rnrn rn rn org.springframework.web.context.ContextLoaderListenerrn rn rn rn rn struts2rn org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterrn rn rn rn struts2rn /*rn rnrnrnrn
java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is r
严重: action: nullrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'goodsBiz' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrnCaused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:115)rn at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)rn at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:354)rn at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:295)rn at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:225)rn at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869)rn at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)rn at javax.servlet.GenericServlet.init(GenericServlet.java:212)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)rn at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)rn at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)rn at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1105)rn at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1203)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)rn at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)rn at java.lang.Thread.run(Unknown Source)rn2010-5-13 13:40:57 org.apache.catalina.core.ApplicationContext logrn信息: Marking servlet action as unavailablern2010-5-13 13:40:57 org.apache.catalina.core.StandardContext loadOnStartuprn严重: Servlet /epai threw load() exceptionrnjavax.servlet.UnavailableExceptionrn at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:880)rn at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)rn at javax.servlet.GenericServlet.init(GenericServlet.java:212)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)rn at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)rn at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)rn at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1105)rn at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1203)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)rn at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)rn at java.lang.Thread.run(Unknown Source)rnrn请各位帮帮忙
一个问题困扰我好几天了,急求。 'sessionFactory' or 'hibernateTemplate' is required
在使用hibernate(3.2)和spring(2.0)进行整合(注解)的时候,继承HibernateDaoSupport,明明注入了SessionFactory 可老是报Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required,十分郁闷,期待高手。。。rnrn=============本来的写法============================rnpackage cn.qtone.xxt.admin.user1;rnrnimport org.hibernate.SessionFactory;rnimport org.springframework.beans.factory.annotation.Autowired;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnimport org.springframework.stereotype.Repository;rnrn@Repositoryrnpublic class UserDao1Imp extends HibernateDaoSupport implements UserDao1rn rn @Autowiredrn private SessionFactory sessionFactory; rn rnrn=======由于报错,从网上找的采用jsr250注解========仍然报错rnpackage cn.qtone.xxt.admin.user1;rnrnimport javax.annotation.PostConstruct;rnimport javax.annotation.Resource;rnimport org.hibernate.SessionFactory;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnimport org.springframework.stereotype.Repository;rnrn@Repositoryrnpublic class UserDao1Imp extends HibernateDaoSupport implements UserDao1rn rn private SessionFactory sessionFactory; rnrn @Resource rn public void setMySessionFacotry(SessionFactory sessionFacotry) rn this.sessionFactory = sessionFacotry; rn rnrn @PostConstruct rn public void injectSessionFactory() rn super.setSessionFactory(sessionFactory); rn rnrn
Spring 注解注入 SessionFactory 空指针异常
# Spring 注解注入 SessionFactory 空指针异常nn条件一napplicationContext.xml文件已经配置了SessionFactory n```n n n n n n n n n org.hibernate.dialect.MySQLDialectn truen n nn n n com/bigfire/entity/Sale.hbm.xmln n n```n条件二 SessionFactory 已经成功注入到Spring容器中,nnApplicationContext act=new ClassPathXmlApplicationContext("applicationContext.xml");n String[] str=act.getBeanDefinitionNames();n for (String string : str) n System.out.println("..."+string);n n![图片说明](https://img-ask.csdn.net/upload/201808/27/1535361242_671235.png)nn这个问题我百度了两天了,有些方法也都试过了,哪位同学解决了麻烦给分享下解决的办法,谢谢了
求助:spring加载sessionFactory报错
tomcat启动时报错,信息如下:rnith the Partitioning, OLAP, Data Mining and Real Application Testing optionsrn18:08:11,585 INFO SettingsFactory:115 - JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0rn18:08:11,726 INFO Dialect:175 - Using dialect: org.hibernate.dialect.Oracle10gDialectrn18:08:11,945 WARN SettingsFactory:126 - Could not obtain connection metadatarnjava.sql.SQLException: Unsupported featurern at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)rn at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)rn at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)rn at oracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:689)rn at oracle.jdbc.OracleDatabaseMetaData.supportsGetGeneratedKeys(OracleDatabaseMetaData.java:4180)rn at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:123)rn at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)rn at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)rn at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)rn at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)rn at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)rn at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)rn at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1203)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)rn at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)rn at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:516)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:593)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)rn18:08:11,960 DEBUG DataSourceUtils:312 - Returning JDBC Connection to DataSourcern18:08:11,991 INFO TransactionFactoryFactory:59 - Using default transaction strategy (direct JDBC transactions)rnrnspring 配置文件为:rnrnrnrn rn rn rn classpath:/db.propertiesrn rn rn rn rn rn $oracle.driverrn rn rn $oracle.urlrn rn rn $oracle.usernamern rn rn $oracle.passwordrn rn rn rn rn rn rn insurance.agent.model.Userrn rn rn rn rn rn org.hibernate.dialect.Oracle10gDialectrn truern truern 50rn truern rn rn rn rn rn rn rnrnrndb.properties 信息如下:rnoracle.driver=oracle.jdbc.driver.OracleDriverrn##oracle.url=jdbc:oracle:thin:@10.0.9.130:1521:oraclernoracle.url=jdbc:oracle:thin:@//10.0.9.130:1521/oraclernoracle.username=proxyuserrnoracle.password=123456rnrn数据库使用的是11g.rnhibernate 使用的是3.2, spring的版本为2.08.rn尝试过直接在java类中写jdbc连接数据,可以连接成功,并能读取数据。rnrn求高手帮忙看看报错是什么原因引起的??? 谢谢。。。。rn
明明注入了SessionFactory 为什么还是报这样的错误呀?'sessionFactory' or 'hibernateTemplate' is required
applicationContext.xmlrnrn[code=Java]rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn org.hibernate.dialect.MySQLDialectrn rn rn rn rn rn mybean/Message.hbm.xmlrn mybean/User.hbm.xmlrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn[/code]rnrnrnUserDaoImpl.javarnrn[code=Java]rnpackage daoimp;rnrnimport java.util.List;rnrnimport org.hibernate.SessionFactory;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnrnimport mybean.User;rnimport dao.UserDao;rnrnpublic class UserDaoImpl extends HibernateDaoSupport implements UserDao rnrn private SessionFactory sessionfactory;rnrn public SessionFactory getSessionfactory() rn return sessionfactory;rn rnrn public void setSessionfactory(SessionFactory sessionfactory) rn this.sessionfactory = sessionfactory;rn rnrn public UserDaoImpl() rn // TODO 自动生成构造函数存根rn rn public void deleteUser(User u) rn getHibernateTemplate().delete(u);rn rnrn public User findByUserName(String name) rn List ul = getHibernateTemplate().find("from User as u where u.name = ?",name);rn if(ul!=null && ul.size()>0)rn return ul.get(0);rn rn return null;rn rnrn public User getUser(int id) rn return (User)getHibernateTemplate().get(User.class, new Integer(id));rn rnrn public int saveUser(User u) rn getHibernateTemplate().save(u);rn return u.getId();rn rnrn public void updataUser(User u) rn getHibernateTemplate().saveOrUpdate(u);rn rnrn public void deleteUser(int id) rn getHibernateTemplate().delete(getHibernateTemplate().get(User.class, new Integer(id)));rn rnrnrnrn[/code]rnrnrnrnrn错误:rn严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerrn[color=#FF0000]org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UserDaoImpl' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' [/color]or 'hibernateTemplate' is requiredrnCaused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:115)
求高手:java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate'
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl' defined in file [D:\Workspaces\OA\oa\WebRoot\WEB-INF\classes\com\oa\dao\impl\UserDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)rn at com.oa.Service.UserServiceTest.testFindUserByName(UserServiceTest.java:25)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)rn at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:236)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:118)rn at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)rn ... 34 morernrn调用代码rn@Testrn public void testFindUserByName() rn ApplicationContext ctxrn = new ClassPathXmlApplicationContext(new String []"application-beans.xml","application-commons.xml");rn UserService userService = (UserService)ctx.getBean("userService");rn User user = userService.findUserByName("longwenjie");rn System.out.println(user.getName()+" | "+user.getMobile());rn rn rnrnservice层代码rnrn@Servicernpublic class UserServiceImpl implements UserService rnrn private UserDao userDao;rn @Overridern public User findUserByName(String name) rn // TODO Auto-generated method stubrn return userDao.findUserByName(name);rn rn @Resourcern public void setUserDao(UserDao userDao) rn this.userDao = userDao;rn rnrn public UserDao getUserDao() rn return userDao;rn rnrnrnrndao层代码rnrn@Componentrnpublic class UserDaoImpl extends HibernateDaoSupport implements UserDao rnrn @Overridern public User findUserByName(String name) rn // TODO Auto-generated method stubrn List userList = getHibernateTemplate().find("from User u where u.name=".concat(name));rn return userList.get(0);rn rnrnrnapplication-beans.xml中的配置rnrnrnrn rn rn rn rn rn rn rnrnrnapplication-commons.xml中的配置rnrnrn rn rnrn rn rn classpath:jdbc.propertiesrn rn rnrn rn rn rn rn rn rnrn rn rn rn rn com.oa.modelrnrn rn rn rn rn rn org.hibernate.dialect.Oracle10gDialectrn rn truern rn rn rn rn rn rnrn rn rn rn rnrn rn rn rn rn rn rnrn rn rn rnrn
诡异的错误,明明注入了sessionFactory,还是报sessionFactory' or 'hibernateTemplate' is required
以下是配置文件:rnrn rn rn rn rn rn rn org.hibernate.dialect.OracleDialectrn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn以下是报错内容:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'whouseService' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrnrn一共建了好几个和whouse类似的bean,配置都一样,别的都不报错,把whouse注释了之后也没问题。rn请大家帮忙解决。
hibernateTemplate在Spring核心配置文件的注入问题
HTTP Status 500 -type Exception reportmessagedescription The server encountered an internal error that prevented it from fulfilling this request.exceptionjava.lang.NullPointerException com.chen.dao
Spring Mybatis配置动态SqlSessionFactory
SqlMap-Config.xmlrn rn rn rn rn rnrnUser.xmlrnrnrn rn rnrn rn select rn User_ID as "User_ID", rn User_Name as "User_Name" rn from UserMaster_Table U where U.User_ID = #User_ID rn rnrnrnUserrnpublic class User // 用户rn private String User_ID; // 员工ID rn private String User_Name; // 员工名称 rnrn public String getUser_ID() rn return User_ID;rn rn public void setUser_ID(String user_ID) rn User_ID = user_ID;rn rn public String getUser_Name() rn return User_Name;rn rn public void setUser_Name(String user_Name) rn User_Name = user_Name;rn rnrnrnjava:rnrnBasicDataSource dataSource=new BasicDataSource();rndataSource.setDriverClassName("..");rndataSource.setUrl("..");rndataSource.setUsername("..");rndataSource.setPassword(".."); rnTransactionFactory transactionFactory = new JdbcTransactionFactory();rnEnvironment environment = new Environment("development", transactionFactory, dataSource);rnConfiguration configuration = new Configuration(environment);rnconfiguration.addMapper(User.class);rnSqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);rnSqlSession sqlSession=sqlSessionFactory.openSession(); rnsqlSession.selectOne("cn.com.sjb.pss.business.entity.User.findUserID", User_ID);rnrn报错rnjava.lang.IllegalArgumentException: Mapped Statements collection does not contain value for cn.com.sjb.pss.business.entity.User.findUserIDrnrn
spring为dao注入sessionFactory的问题
dao继承了HibernateDaoSupport类并实现了相应的接口。rnrn所以需要为其注入sessionFactory。rnrn在xml中配置了sessionFactory。rnrn由于用的是基于注解的配置。rnrndao的配置就用注解,不在xml中配置了。rnrndao中没有设置sessionFactory属性rnrn在applicationContext.xml中配置了default-autowire="byName"rn为什么就可以为这个dao类注入了sessionFactory。rnrn而配置了default-autowire="byType"和不配置default-autowire都会说无法为dao注入sessionFactory。rnrn这是为什么 ?rnrn
spring最简单的问题,sessionFactory无法注入
今天刚接触spring,照着例子做。rnapplicationContext.xmlrn[code=XML]rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn org.hibernate.dialect.SQLServerDialectrn rn rn rn rn rn rn com/User.hbm.xmlrn rn rn rn rn rn rn rn rn rnrn[/code]rn数据库链接是没有问题的,其他项目里正常。rnUserDaoImpl.javarn[code=Java]rnpackage com;rnrnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnrnpublic class UserDaoImpl extends HibernateDaoSupport implements UserDao rnrn @Overridern public void login() rn // TODO Auto-generated method stubrn System.out.println(this.getSessionFactory());rn rnrnrn[/code]rnrnlogin里面什么都不做就输出sessionFactory,但是输出是null。rnrn不知道哪里出了问题?
S2SH 中的Spring sessionFactory注入配置问题
环境是: Struts 2.1.8.1 + Spring 3.0 + Hibernate 3.3.2GArnrn在配置spring 时如果是一个dao的话,就不报错,但是如果有两个dao的话就报:rnInvocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrnrn[code="xml"]rnrnrnrn rn rn rnrn rn rn rn rn rn rn rnrn rn rn rnrn[/code]rnrn以下是dataSource和sessionFactory的代码rnrn[code="xml"]rnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rn rn classpath:/com/liutan/beanrn rn rn rn rn org.hibernate.dialect.MySQLDialectrn truern truern autorn truern truern jdbc:mysql://localhost:3306/winmrprn com.mysql.jdbc.Driverrn rootrn rootrn rn rn rnrnrn[/code]
spring的HibernateTemplate
spring的hibernateTemplate是有自带session关闭吗?rnpublic void lookMyAttends(int empId)rn rn Employee emp = (Employee)this.hibernateTemplate.get(Employee.class, empId);rn Set attends=emp.getAttends();rnrn for(Attend attend:attends)rn System.out.println("id: "+attend.getId());rn System.out.println("type: "+attend.getAttendType().getType());rn System.out.println("employeeName: "+attend.getEmployee().getName());rn rn rnrn在这个方法里获取Employee,而且employee里面有一个集合Attends通过getAttends获得。但是this.hibernateTemplate.get(Employee.class, empId);执行完后貌似session就关闭了,所以在后面的emp.getAttends();执行会报错,说no session or session closed;rnrn求大神指导,解释一下HibernateTemplate的session管理和事务管理
spring 注入失败报错
报错代码片段: Error creating bean with name 'itemServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire...
Spring 自动注入报错
哪位大侠给瞅瞅啊rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: richeninfo.dao.UserMapper richeninfo.service.UserService.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [richeninfo.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rnRelated cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\sts\configSystem\target\classes\richeninfo\dao\UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\sts\configSystem\target\classes\richeninfo\mapping\UserMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum const class org.apache.ibatis.type.JdbcType.Integerrn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)rn at richeninfo.test.UserTest.findUser(UserTest.java:24)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)rn at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)rn at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:309)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: richeninfo.dao.UserMapper richeninfo.service.UserService.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [richeninfo.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)rn ... 36 morernCaused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [richeninfo.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:949)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)rn ... 38 morernRelated cause:rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\sts\configSystem\target\classes\richeninfo\dao\UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\sts\configSystem\target\classes\richeninfo\mapping\UserMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum const class org.apache.ibatis.type.JdbcType.Integerrn at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)rn at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1391)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getTypeForFactoryBean(AbstractBeanFactory.java:1357)rn
spring mvc 注入报错
错误信息如下:rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.service.UploadService com.controller.UploadController.uploadService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.UploadDao com.service.UploadService.uploadDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.dao.UploadDao.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)rn at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)rn at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)rn at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)rn at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)rn at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)rn at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)rn at javax.servlet.GenericServlet.init(GenericServlet.java:158)rn at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)rn at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)rn at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.service.UploadService com.controller.UploadController.uploadService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.UploadDao com.service.UploadService.uploadDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.dao.UploadDao.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)rn ... 36 morernCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.UploadDao com.service.UploadService.uploadDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.dao.UploadDao.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1145)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1069)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)rn ... 38 morern....
spring 循环注入报错
2019-01-21 17:17:51,705 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 't...
Spring 注入报错
下面的是接口类和实现类public interface CompactDisc { void play(); }public class SgtPeppers implements CompactDisc{ private String name="1 number"; private String title="xiulianaiqing"; public voi
HibernateDaoSupport的SessionFactory的注入
我创建了一个空的类,利用Spring在这个空的类注入了SessionFactory并且继承了HibernateDaoSupport,然后我再写了一个BaseDao来继承这个已经继承了HibernateDaoSupport,也注入过sessionFactory的空类。然后我在继承BaseDao写一个UserDao的过程中为什么还要我注入SessionFactory才行?
hibernate 注入sessionFactory
刚刚完成的ssh项目中是用的spring依赖注入方式注入的sessionFactory,具体代码如下rn[code=text]rnrn rn rn rn rn com/citycard/pojo/User.hbm.xmlrn com/citycard/pojo/City.hbm.xmlrn com/citycard/pojo/Scenic.hbm.xmlrn com/citycard/pojo/Rss.hbm.xmlrn com/citycard/pojo/News.hbm.xmlrn com/citycard/pojo/Survey.hbm.xmlrn com/citycard/pojo/Question.hbm.xmlrn com/citycard/pojo/Answer.hbm.xmlrn com/citycard/pojo/Opinion.hbm.xmlrn com/citycard/pojo/Comment.hbm.xmlrn rn rn rn rn org.hibernate.dialect.MySQL5Dialectrn falsern falsern rn rn rn[/code]rn然后通过@Autowired注解方式直接使用sessionFactory实例。rn我想问一下用这种方式是不是就不需要通过 Configuration来创建SessionFactory了rn[code=java]rn Configuration cfg = new Configuration(); // 获得配置信息对象rn SessionFactory sf = cfg.configure().buildSessionFactory(); //解析并建立Session工厂rn[/code]rn因为我rn@autowiredrn SessionFactory sessionFactory;之后就可以直接用sessionFactory得到session了。
HibernateDaoSupport注入SessionFactory问题
当我们在spring整合hibernate时候需要注入一个SessionFactoryrnrn又因为每个dao都必须要注入这个对象rnrn所以我把提出一个dao父类出来rnrn在里面使用spring注解的方法注入一个SessionFactory对象,这个整个项目就只需要写一个注入rnrn[code=Java]rnpublic abstract class BaseDaoImplrn extends HibernateDaoSupport implements BaseDao rnrn /**rn * 实体类的类型rn */rn private Class entityClass;rnrn /**rn * rn * @return 泛型的类型rn */rn public Class getEntityClass() rn return entityClass;rn rnrn private SessionFactory localSessionFactory;rnrn /**rn * rn * @param factoryrn */rn @Resource(name = "sessionFactory")rn public void setLocalSessionFactory(Object sessionFactory) rn try rn System.out.println("--------------"+sessionFactory.getClass());rn /*rn * this.localSessionFactory = sessionFactory;rn * System.out.println(localSessionFactory);rn * [color=#FF0000]setSessionFactory(localSessionFactory);[/color] */rn System.out.println("success..........................");rn catch (Exception e) rn e.printStackTrace();rn rn rnrn[/code]rnrn这个类继承了HibernateDaoSupport我写了一个LocalSessionFactory方法使用@Resource(name="sessionFactory")rn这个注入sessionFactory但是出现了bugrn[code=Java]rnCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dicitonaryDao' defined in file [G:\erp\erp\web\WEB-INF\system\spring-system.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredrn[/code]rn原来我把LocalSessionFactory的类型定义为LocalSessionFactoryBeanrn然后使用getObject()方法强转在调用HibernateDaoSupport的setSessionFactory方法注入SessionFactory,不行rnrnrn请高手指教
sessionFactory注入问题
[color=#FF0000][color=#FF0000]我是java 新手,遇到点问题,请大家帮忙rnsessionFactory注入总出错,我用的是struts2+spring3+hebernate4,下面是代码[/color]rnweb.xml[/color]rn[code=java]rnrnrnrn contextConfigLocationrn classpath:applicationContext.xmlrnrnrnrn openSessionInViewFilterrn org.springframework.orm.hibernate4.support.OpenSessionInViewFilterrn rn sessionFactoryBeanNamern sessionFactoryrn rn rn rn rn openSessionInViewFilter rn /* rn rnrnrn struts2rn rn org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterrn rnrnrn rn rn log4jConfigLocation rn classpath:log4j.properties rn rnrnrn struts2rn /*rnrnrnrn /login/login.jsprnrnrnrn rn org.springframework.web.context.ContextLoaderListenerrn rnrnrn[/code]rnrnapplicationContext.xmlrn[code=java]rn rnrnrn rn rn rn com.microsoft.sqlserver.jdbc.SQLServerDriverrn rn rn jdbc:sqlserver://JF:1433;DatabaseName=Extensiondatabasern rn rn sarn rn rn 123456rn rn rn rn rn rn rn rn org.hibernate.dialect.SQLServerDialect rn true rn threadrn rn rn rn rn classespackage/model/Unittable.hbm.xml rn rn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rn rn rn rnrn[/code]rnrnBaseDAO.javarn[code=java]package classespackage.dao;rnrnimport java.io.Serializable;rnimport java.util.List;rnrnpublic interface BaseDAO rn rn void insert(T t); rn rn void delete(T t); rn rn void update(T t); rn rn T queryById(String id); rn rn List queryAll(); rn rn rn[/code]rnrnGenericDAO.javarn[code=java]public class GenericDAO implements BaseDAO rn @Autowired rn private SessionFactory sessionFactory; rn public void setSessionFactory(SessionFactory sessionFactory) rn this.sessionFactory = sessionFactory;rn rn rn public Session getSession() rn return sessionFactory.getCurrentSession(); rn rn[/code]rnrn[color=#FF0000]将sessionFactory注入到GenericDAO类中,Debug出sessionFactory=nullrn若将GenericDAO类换成下面代码,并去掉applicationContext.xml中的注入代码,会出现同样问题[/color]rn[code=java]public class GenericDAO implements BaseDAO rn @Autowired rn private SessionFactory sessionFactory; rn private ApplicationContext ctx; rn rn public Session getSession() rn String[] configLocations = new String[] "classpath:applicationContext-*.xml"; rn ctx = new ClassPathXmlApplicationContext(configLocations); rn sessionFactory = ctx.getBean("sessionFactory", SessionFactory.class); rn return sessionFactory.getCurrentSession(); rn rn[/code]
BasicDAO sessionFactory注入问题
[code=Java][/code]这是我的Spring 配置文件rn[code=Java]rnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn org.hibernate.dialect.MySQLDialectrn rn rn rn rn rn org/lostrue/model/Logintable.hbm.xmlrn rn rn rn [color=#FF0000]rn rn [/color]rn rn rn rn rn rn rn rn rn rn rn rnrn[/code]rn这是我BasicDAO的代码rn[code=Java]package org.lostrue.dao;rnrnimport org.hibernate.Session;rnimport org.hibernate.SessionFactory;rnrn/**rn * @author intonern *rn */rnpublic class BasicDAO rn private SessionFactory sessionFactorya ;rn rn public SessionFactory getSessionFactorya() rn return sessionFactorya;rn rn public void setSessionFactorya(SessionFactory sessionFactorya) rn this.sessionFactorya = sessionFactorya;rn rn public Session getSession()rn return this.sessionFactorya.openSession();rn rnrnrn[/code]rn以前未用过Struts + Hibernate + Spring结合做过开发rn最近会要用上,于是自己做做,总是拿不到session,抛空指针异常!rnrnstruts配置文件rn[code=java]rnrnrnrnrn rn rn rnrn rnrn rn rn rn rn rn rn rnrn rnrn rn rn rn rnrn[/code]rn谢谢了
sessionFactory 没有注入?
java.lang.NullPointerExceptionrn at login_system.DaoIpml.UsersDaoHibernate.get(UsersDaoHibernate.java:59)rn at test.TestUserDaoImpl.testsave(TestUserDaoImpl.java:14)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rnrntomcat启动成功rnrn[b]applicationContext.xml[/b]rn[code=Java]rnrnrnrn rn rn rn rn rn rn rn rn rnrn rn rn rn rn Users.hbm.xmlrn rn rn rn rn rn org.hibernate.dialect.MySQLDialectrn rn truern updatern 20rn rn rn rnrn rn rn rnrnrnrn[/code]rnrn[b]UsersDaoHibernate.java[/b]rn[code=Java]rnpackage login_system.DaoIpml;rnrnimport java.util.List;rnrnimport login_system.Dao.UsersDao;rnimport login_system.bean.HibernateUtils;rnimport login_system.bean.Users;rnrnimport org.hibernate.Session;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnrnpublic class UsersDaoHibernate extends HibernateDaoSupport implements UsersDaornrnrn public void delete(Users users)rn rn getHibernateTemplate().delete(users);rnrn rnrn public void delete(int id)rn rn getHibernateTemplate().delete(rn getHibernateTemplate().get(Users.class, id));rnrn rnrn public List findAll()rn rn return getHibernateTemplate().find("from Users");rn rnrn public Users findUsersByName(String name)rn rn List li = getHibernateTemplate().find("from Users ac where ac.name=? ",rn name);rn if (li != null && li.size() > 0)rn rn return (Users) li.get(0);rn rn return null;rn rnrn public Users findUsersByNameAndPassword(String name, String password)rn rn List li = getHibernateTemplate().find(rn "from Users ac where ac.name=? and ac.password=? ",rn new String[]rn name, password );rn if (li != null && li.size() > 0)rn rn return (Users) li.get(0);rn rn return null;rn rnrn public Users get(int id)rn rn return (Users)getHibernateTemplate().load(Users.class, id);rn rnrn public void save(Users users)rn rn getHibernateTemplate().save(users);rnrn rnrn public void update(Users users)rn rn getHibernateTemplate().update(users);rnrn rnrnrn[/code]rn[b]测试代码[/b]rn[code=Java]rnpackage test;rnrnimport junit.framework.TestCase;rnimport login_system.DaoIpml.UsersDaoHibernate;rnimport login_system.bean.Users;rnrnpublic class TestUserDaoImpl extends TestCasernrn public void testsave()rn rn tryrn UsersDaoHibernate h1=new UsersDaoHibernate();rn rn System.out.print(h1.get(1).getName());rn rn catch(Exception e)rn rn e.printStackTrace();rn rn// Users u1 =new Users();rn// u1.setName("admin");rn// u1.setPassword("123456");rn// u1.setEmail("wjk2813@163.com");rn// h1.save(u1);rn rnrn[/code]rnrn数据库里已经有数据了 我直接用session去读取又可以rn用UsersDaoHibernate 为什么老是抛出空异常 是sessionFactory的问题还是那个getHibernateTemplate()的问题呀
sessionFactory没有注入。
通用daorn[code=Java]rnpackage com.glot.sst.persist;rnrnimport org.hibernate.criterion.DetachedCriteria;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnimport org.springframework.transaction.annotation.Propagation;rnimport org.springframework.transaction.annotation.Transactional;rnrnimport java.io.Serializable;rnimport java.util.List;rnrn@Transactionalrnpublic class BaseDao extends HibernateDaoSupport implements IBaseDaornrn private Class entityClass;rnrn public void save(T entity) rn getSession().clear();rn this.getHibernateTemplate().saveOrUpdate(entity);rn rnrn public void update(T entity) rn this.getSession().clear();rn this.getHibernateTemplate().delete(entity);rn rnrn public T findById(PK id) rn return (T)this.getHibernateTemplate().get(entityClass,id);rn rnrn public List findAll() rn DetachedCriteria criteria = DetachedCriteria.forClass(entityClass);rn return this.getHibernateTemplate().findByCriteria(criteria);rn rnrn public List findListByParms(String hql,Object[] values)rn return this.getHibernateTemplate().find(hql,values);rn rnrn public void delete(T entity) rn this.getSession().clear();rn this.getHibernateTemplate().delete(entity);rn rnrn public Object findUnique(String hql, Object[] values) rn List list = getHibernateTemplate().find(hql,values);rn if(list.size() == 0)rn return null;rn elsern return list.get(0);rn rn rnrnrn[/code]rnrnspring配置rn[code=Java]rn rn rn rn[/code]rn其他dao继承上面通用dao,启动服务还是报那个子类不能建立,sessionFactory or HibernateTemplate is requiredrnBasedao明明就对sessionFactory进行注入了啊.
sessionFactory注入问题?
rn怎么在Java代码中显式注入sessionFactory?rnrn不是在xml里面注入。是在代码中注入噢。rnrn[code=java]rnpublic class BatchJob1 extends QuartzJobBeanrn private SessionFactory sessionFactory;rnrn public SessionFactory getSessionFactory() rn return sessionFactory;rn rnrn public void setSessionFactory(SessionFactory sessionFactory) rn this.sessionFactory = sessionFactory;rn rnrn[/code]
spring boot 配置redis 报错 NOAUTH Authentication required
spring boot 配置redis报错NOAUTH Authentication requiredrnrn配置文件application.propertiesrn# REDIS (RedisProperties)rn# Redis\u6570\u636E\u5E93\u7D22\u5F15\uFF08\u9ED8\u8BA4\u4E3A0\uFF09rnspring.redis.database=0rn# Redis\u670D\u52A1\u5668\u5730\u5740rnspring.redis.host=127.0.0.1rn# Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3rnspring.redis.port=6379rn# Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09rnspring.redis.password=foobaredrn# \u8FDE\u63A5\u6C60\u6700\u5927\u8FDE\u63A5\u6570\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09rnspring.redis.pool.max-active=8rn# \u8FDE\u63A5\u6C60\u6700\u5927\u963B\u585E\u7B49\u5F85\u65F6\u95F4\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09rnspring.redis.pool.max-wait=-1rn# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5rnspring.redis.pool.max-idle=8rn# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5rnspring.redis.pool.min-idle=0rn# \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09rnspring.redis.timeout=0rnrnrnrnpom.xmlrnrn org.springframework.bootrn spring-boot-starter-parentrn 1.3.2.RELEASErn rn rnrn rn UTF-8rn 1.7rn rnrn rn rn org.springframework.bootrn spring-boot-starterrn rnrn rn org.springframework.bootrn spring-boot-starter-testrn testrn rnrn rn org.springframework.bootrn spring-boot-starter-redisrn rnrn rnrnrnrn测试类rnimport com.didispace.domain.User;rnimport org.junit.Assert;rnimport org.junit.Test;rnimport org.junit.runner.RunWith;rnimport org.springframework.beans.factory.annotation.Autowired;rnimport org.springframework.boot.test.SpringApplicationConfiguration;rnimport org.springframework.data.redis.core.RedisTemplate;rnimport org.springframework.data.redis.core.StringRedisTemplate;rnimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;rnrnrn@RunWith(SpringJUnit4ClassRunner.class)rn@SpringApplicationConfiguration(Application.class)rnpublic class ApplicationTests rnrn @Autowiredrn private StringRedisTemplate stringRedisTemplate;rnrn @Autowiredrn private RedisTemplate redisTemplate;rnrn @Testrn public void test() throws Exception rnrn // 保存字符串rn stringRedisTemplate.opsForValue().set("aaa", "111");rn Assert.assertEquals("111", stringRedisTemplate.opsForValue().get("aaa"));rnrn // 保存对象rn// User user = new User("超人", 20);rn// redisTemplate.opsForValue().set(user.getUsername(), user);rn//rn// user = new User("蝙蝠侠", 30);rn// redisTemplate.opsForValue().set(user.getUsername(), user);rn//rn// user = new User("蜘蛛侠", 40);rn// redisTemplate.opsForValue().set(user.getUsername(), user);rn//rn// Assert.assertEquals(20, redisTemplate.opsForValue().get("超人").getAge().longValue());rn// Assert.assertEquals(30, redisTemplate.opsForValue().get("蝙蝠侠").getAge().longValue());rn// Assert.assertEquals(40, redisTemplate.opsForValue().get("蜘蛛侠").getAge().longValue());rnrn rnrnrnrnrndebug发现RedisTemplate对象中的信息不是我配置的内容,我配置的是127.0.0.1端口但是读取到的是localhost,我配置了秘密但是读取到密码是nullrn[img=https://img-bbs.csdn.net/upload/201608/25/1472118966_845410.png][/img][img=https://img-bbs.csdn.net/upload/201608/25/1472118983_307155.png][/img]
Spring时间类型的注入配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/sc
spring注解注入的配置
xml文件的配置: xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3
相关热词 c#部署端口监听项目、 c#接口中的属性使用方法 c# 昨天 c#func链接匿名方法 c#怎么创建文件夹 c#从键盘接收空格 c#da/ad c#部门请假管理系统 c#服务器socket c# 默认的访问修饰符