Struts文件是在xml配置的,hibernate是连接数据库的,Spring是applicationContext里面配置的,每个实现的方式看自己所需要的
你没试过三大框架的annotaion配置?
@angelshelter: 几个配置文件如下:
spring-database.xml(这个文件基本不变,有新的dao在底下加入一行即可。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>${jdbc.driverClassName}</value></property>
<property name="url"><value>${jdbc.url}</value></property>
<property name="username"><value>${jdbc.username}</value></property>
<property name="password"><value>${jdbc.password}</value></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configurationClass"><value>org.hibernate.cfg.AnnotationConfiguration</value></property>
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="configLocation"><value>/hibernate.cfg.xml</value></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
<property name="dataSource"><ref bean="dataSource"/></property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor"><ref bean="transactionInterceptor"/></property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
<!-- ========================= DAO DEFINITIONS ========================= -->
<bean id="testDao" class="org.steeven.TestDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- ========================= DAO DEFINITIONS ========================= -->
<bean id="mitService" class="org.steeven.TestServiceImpl"></bean>
</beans>
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="default-lazy">false</property>
<!-- 用于hibernate持久化的对象" -->
<mapping class="org.steeven.Test"/>
<listener type="pre-update" class="org.hibernate.validator.event.ValidatePreUpdateEventListener"/>
<listener type="pre-insert" class="org.hibernate.validator.event.ValidatePreInsertEventListener"/>
</session-factory>
</hibernate-configuration>
类似于这种