解决方案 »
- jsp页面javascript 用form表单提交出错!Object doesn't support this property or method
- java下ORM的LINQ实现JoSQL!!
- 做了块一年j2ee,没事了,非软件公司,想跳到软件公司去
- 谁能给我解释一下什么是FacesContext。在JSF框架中有什么作用?
- <html:text> 如何初始化?
- 作为一个后备(现在大三),想问问在这里的师兄师姐门一个关乎目标未来的问题
- .NET已经进入与JAVA分庭抗礼的时期了。vs2005+sqlserver2005+vista操作系统,不论从性能和安全性方面都会走上一个前所未有的高度...
- 请达人、高手、TX们帮我把开发环境搭一个出来。
- tomcat进行administation的用户密码是什么?
- j2ee部署问题,请教高手!出错!
- 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;就可以用了