各位CSDN的朋友们,你们好。最近刚刚使用spring2.5.6 感觉不错
本人想使用annotation减少spring bean的配置,尤其是DAO的配置,在我的项目中有许多DAO,因此想使用注释的方式来减少XML中的配置我的写法如下
applicationContext.xml
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="com.zhekou" />
<!-- dataSource config -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://127.0.0.1:3306/zhekou</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>admin</value>
</property>
</bean>
<!-- 该 BeanPostProcessor 将自动起作用,对标注 @Autowired 的 Bean 进行自动注入 -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<!-- SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>com/zhekou/composit/model/City.hbm.xml</value>
<value>com/zhekou/composit/model/Region.hbm.xml</value>
<value>com/zhekou/composit/model/Community.hbm.xml</value>
<value>com/zhekou/user/model/Userspace.hbm.xml</value>
<value>com/zhekou/user/model/User.hbm.xml</value>
<value>com/zhekou/user/model/Userinfo.hbm.xml</value>
<value>com/zhekou/user/model/Userpermission.hbm.xml</value>
<value>com/zhekou/store/model/Crossedstore.hbm.xml</value>
<value>com/zhekou/store/model/Store.hbm.xml</value>
<value>com/zhekou/store/model/Storeinfo.hbm.xml</value>
<value>com/zhekou/store/model/Firststorekind.hbm.xml</value>
<value>com/zhekou/store/model/Storekind.hbm.xml</value>
<value>com/zhekou/visitor/model/Storevisitor.hbm.xml</value>
<value>com/zhekou/dynamic/model/Dynamic.hbm.xml</value>
<value>com/zhekou/map/model/StoreMap.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.configurationResourceName">ehcache.xml</prop>
</props>
</property>
</bean> <!-- 模糊匹配需要拦截的方法 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<!-- <aop:pointcut id="allServiceMethod" expression="execution(* com.zhekou.region.dao.*.*.*(..))" /> -->
<aop:pointcut id="allServiceMethod" expression="execution(* com.zhekou.*.dao.*.*(..))" />
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
</aop:config>
<!-- 定义事务管理器,使用适用于Hibernte的事务管理器-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- HibernateTransactionManager bean需要依赖注入一个SessionFactory bean的引用-->
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 使Spring关注Annotation -->
<context:annotation-config/>
</beans>
在DAO实现类的写法
@Repository("storeDAO")
public class StoreDAOImpl extends HibernateDaoSupport implements StoreDAO在SERVICE实现类的写法
@Service("storeService")
@Transactional
public class StoreServiceImpl extends BaseService implements StoreService{
@Autowired
private StoreDAO storeDAO ;在ACTION中的写法
StoreService storeService = (StoreService)getWebApplicationContext().getBean("storeService");
如果我这样没在XML里配置storeDAO的话 那么就会出错误,下面是错误信息,相反如果配置了storeDAO,并且把sessionFactory注入进去就不会出错,就像这样就不会出错了
<bean id="storeDAO" class="com.zhekou.store.dao.impl.StoreDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
请教各位为何出错?如何解决?我想让我的配置文件中没有一行DAO的配置。。
本人想使用annotation减少spring bean的配置,尤其是DAO的配置,在我的项目中有许多DAO,因此想使用注释的方式来减少XML中的配置我的写法如下
applicationContext.xml
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="com.zhekou" />
<!-- dataSource config -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://127.0.0.1:3306/zhekou</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>admin</value>
</property>
</bean>
<!-- 该 BeanPostProcessor 将自动起作用,对标注 @Autowired 的 Bean 进行自动注入 -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<!-- SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>com/zhekou/composit/model/City.hbm.xml</value>
<value>com/zhekou/composit/model/Region.hbm.xml</value>
<value>com/zhekou/composit/model/Community.hbm.xml</value>
<value>com/zhekou/user/model/Userspace.hbm.xml</value>
<value>com/zhekou/user/model/User.hbm.xml</value>
<value>com/zhekou/user/model/Userinfo.hbm.xml</value>
<value>com/zhekou/user/model/Userpermission.hbm.xml</value>
<value>com/zhekou/store/model/Crossedstore.hbm.xml</value>
<value>com/zhekou/store/model/Store.hbm.xml</value>
<value>com/zhekou/store/model/Storeinfo.hbm.xml</value>
<value>com/zhekou/store/model/Firststorekind.hbm.xml</value>
<value>com/zhekou/store/model/Storekind.hbm.xml</value>
<value>com/zhekou/visitor/model/Storevisitor.hbm.xml</value>
<value>com/zhekou/dynamic/model/Dynamic.hbm.xml</value>
<value>com/zhekou/map/model/StoreMap.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.configurationResourceName">ehcache.xml</prop>
</props>
</property>
</bean> <!-- 模糊匹配需要拦截的方法 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<!-- <aop:pointcut id="allServiceMethod" expression="execution(* com.zhekou.region.dao.*.*.*(..))" /> -->
<aop:pointcut id="allServiceMethod" expression="execution(* com.zhekou.*.dao.*.*(..))" />
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
</aop:config>
<!-- 定义事务管理器,使用适用于Hibernte的事务管理器-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- HibernateTransactionManager bean需要依赖注入一个SessionFactory bean的引用-->
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 使Spring关注Annotation -->
<context:annotation-config/>
</beans>
在DAO实现类的写法
@Repository("storeDAO")
public class StoreDAOImpl extends HibernateDaoSupport implements StoreDAO在SERVICE实现类的写法
@Service("storeService")
@Transactional
public class StoreServiceImpl extends BaseService implements StoreService{
@Autowired
private StoreDAO storeDAO ;在ACTION中的写法
StoreService storeService = (StoreService)getWebApplicationContext().getBean("storeService");
如果我这样没在XML里配置storeDAO的话 那么就会出错误,下面是错误信息,相反如果配置了storeDAO,并且把sessionFactory注入进去就不会出错,就像这样就不会出错了
<bean id="storeDAO" class="com.zhekou.store.dao.impl.StoreDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
请教各位为何出错?如何解决?我想让我的配置文件中没有一行DAO的配置。。
解决方案 »
- 这个网站是用什么开发的?asp?php?还是??
- Jsp中怎样发送邮件啊???
- 用common-fileupload组件进行文件上传,但是获得items.size()为0。心急如焚,求大家帮帮我。
- 在线等,有的分全送了,问关于DTree显示的问题!!!!!!!!!
- web service
- 请教,关于jdom的问题
- Tomcat5.0 下webapps中设置了自己的目录但是WEB-INF/classes中的类无法找到
- 用weblogic7,jbuilder8,oracle9做struta1.1时出现jndi错误,急!
- 新手求救!!!
- 如何获得本机的以太网地址 JAVA
- hibernate多对多关系 拆分成2个一对多 查询的的问题
- 每隔几秒把数据库里的数据取出来
09:49:15,670 ERROR ContextLoaderPlugIn:229 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'storeDAO' defined in file [E:\yangmh's work space\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\zkjsp\WEB-INF\classes\com\zhekou\store\dao\impl\StoreDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:354)
at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:295)
at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:225)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:871)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:359)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:117)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 35 more
<?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: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-2.5.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.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="true">
<context:annotation-config />
<context:component-scan base-package="com.inventec.*"></context:component-scan> <!-- EntityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager"/>
<property name="jpaProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.query.substitutions=true 'Y', false 'N'
hibernate.cache.use_second_level_cache=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
</value>
<!-- Turn batching off for better error messages under PostgreSQL -->
<!-- hibernate.jdbc.batch_size=0 -->
</property>
</bean> <bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list>
<value>classpath:META-INF/persistence.xml</value>
</list>
</property>
<property name="defaultDataSource" ref="dataSource"/>
</bean> <!-- Needed so the @PersistenceUnit annotation is recognized -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <!-- Transaction manager for a single EntityManagerFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
多谢你的回复 但是我是使hibernate做持久层,你的是jpa的 ,所以只能继续等人了。
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="hibernateProperties">
<props>
hibernate配置信息
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.xxxxx.*.*</value>
</list>
</property>
</bean>
一般这样配的<bean id="storeDAO" class="com.zhekou.store.dao.impl.StoreDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<context:annotation-config/><!-- 打开AOP织入功能 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 打开Spring扫描创建Bean功能 -->
<context:component-scan base-package="你的包名"/>
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <context:annotation-config />
<context:component-scan base-package="com.test.*" /> <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="driverUrl" value="jdbc:mysql://localhost:3306/ibatisstudy?characterEncoding=UTF-8" />
<property name="user" value="root" />
<property name="password" value="111111" />
<property name="alias" value="demo-ds" />
<property name="maximumConnectionCount" value="10" />
<property name="minimumConnectionCount" value="2" />
</bean>
<tx:annotation-driven transaction-manager="txManager" /> <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="/WEB-INF/persistence.xml"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true"/>
<property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
</property>
</bean>
<bean id="sBookDao" class="com.test.dao.SBookDao" autowire="byType"></bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <context:annotation-config />
<context:component-scan base-package="com.vcm.*" /> <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="driverUrl" value="jdbc:mysql://localhost:3306/ibatisstudy?characterEncoding=UTF-8" />
<property name="user" value="root" />
<property name="password" value="111111" />
<property name="alias" value="demo-ds" />
<property name="maximumConnectionCount" value="10" />
<property name="minimumConnectionCount" value="2" />
</bean>
<tx:annotation-driven transaction-manager="txManager" /> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory" />
</bean>
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<!-- 是否将运行期生成的SQL输出到日志以供调试 -->
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/test/orm/Book.hbm.xml</value>
</list>
</property>
</bean>
<bean id="sBookDao" class="com.vcm.dao.SBookDao" autowire="byType"></bean>
</beans>
但是你得想想用下面注解怎么才能把sessionFactory注入dao中@Repository("storeDAO")
public class StoreDAOImpl extends HibernateDaoSupport implements StoreDAO
看看这个