67,515
社区成员
发帖
与我相关
我的任务
分享
这是我的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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/lostrue/model/Logintable.hbm.xml</value>
</list>
</property>
</bean>
<bean id="Factory" class="org.lostrue.dao.BasicDAO">
<property name="sessionFactorya" ref="sessionFactory"/>
</bean>
<bean id="logindao" class="org.lostrue.dao.impl.UserLoginDAOimpl"
scope="prototype" />
<bean id="loginservice"
class="org.lostrue.service.impl.UserLoginServiceimpl"
scope="prototype">
<property name="logindao">
<ref bean="logindao" />
</property>
</bean>
<bean name="/userLogin"
class="org.lostrue.struts.action.UserLoginAction" scope="prototype">
<property name="loginservice">
<ref bean="loginservice" />
</property>
</bean>
</beans>
package org.lostrue.dao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
/**
* @author intone
*
*/
public class BasicDAO {
private SessionFactory sessionFactorya ;
public SessionFactory getSessionFactorya() {
return sessionFactorya;
}
public void setSessionFactorya(SessionFactory sessionFactorya) {
this.sessionFactorya = sessionFactorya;
}
public Session getSession(){
return this.sessionFactorya.openSession();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="userLoginForm" type="org.lostrue.struts.form.UserLoginForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="userLoginForm"
input="/userLogin.jsp"
name="userLoginForm"
path="/userLogin"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward
name="err"
path="/err.jsp"/>
<forward
name="succ"
path="/succ.jsp"/>
</action>
</action-mappings>
<message-resources parameter="org.lostrue.struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/beans.xml" />
</plug-in>
</struts-config>
public class UsersDAO extends HibernateDaoSupport {
//findbyId 等DAO方法。不用考虑session
public Users FindById(Long Id) {
...
}
}
<!-- DAO -->
<bean id="alarmDAO" class="com.telestone.web.dao.AlarmDAO">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>