解决方案 »
- 请教关于addFieldError信息在页面显示出来后导致网页背景图片消失的问题。。
- ibatis配置文件问题报错了
- 线程的类载入器究竟怎么用,这个在哪种情况下用到?
- 马上毕业 给自己一个目标了 有经验的帮忙指正一下
- 一个奇怪的java基础问题
- 我现在做的系统出现了重复i定位的问题,是一个关于arcGIS在java上的应用
- jsp与js的访问
- 求解:weblogic,websphere,tomcat有什么用处和区别
- 设计模式能解决这样的问题吗?
- 我安装了jdk1.5和tomcat5.0.29,为什么不能解析虚拟目录里的jsp文件,在线等
- hibernate多对多的一个疑问
- 关于Filter的一点问题
ClassPathXmlApplicationContext c = new ClassPathXmlApplicationContext(
"applicationContext.xml");
TbRoleDAO roleDAO = (TbRoleDAO) c.getBean("roleDAO");相当于 TbRoleDAO roleDAO = new TbRoleDAO(); 之后就和spring 没有关系了,你还是看看
TbRoleDAO吧
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
</bean>
这一段配置是在干嘛呢? 我搞不明白。SessionFactory就算是配好了?如果加上事务 是这样的么?<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="merge*" propagation="REQUIRED" />
<tx:method name="find*" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
<tx:method name="show*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="interceptorPointCuts" expression="execution(* dao.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" />
</aop:config>
<!--事务管理配置结束 --> <bean id="baseDAO" class="dao.BaseHibernateDAO"></bean>
<bean id="roleDAO" class="dao.TbRoleDAO"></bean>
</beans>
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="permissionDAO" class="dao.impl.TbPermissionDAO">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
必须这样才行TbPermissionDAO 是继承了 BaseHibernateDAO 的
本以为对父类注入SessionFactory后 子类就不用注入了。但是不行啊
子类(TbPermissionDAO 还是注要入一遍 SessionFactory )
否则说 'sessionFactory' or 'hibernateTemplate' is required我记得别人说可以通过给父DAO注入SessionFactory 子类就不用注入了的
看了你的 不错 但是我的疑问还是没有解决。
我有一个DAO父类 已经注入了SessionFactory , 结果子类还是要再次注入才行。。
否则服务器启动都错但是我记得是可以通过给父类注入 ,子类就不用注入的。。要不然配置文件会很长很长很长
当spring这个bean容器中有了hibernateTemplate时,
我们只要在想用到它的任何地方写上:@Resource
private HibernateTemplate hibernateTemplate;就可以用了