`
piziyan
  • 浏览: 70467 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Struts+Hibernate+Spring配置

阅读更多
struts配置:

<struts-config>
  <data-sources /> 
<form-beans>
  <form-bean name="userForm" type="org.tie.struts.form.UserForm" /> 
  </form-beans>
  <global-exceptions /> 
  <global-forwards /> 
<action-mappings>
<action attribute="userForm" 
        input="/index.jsp" 
        name="userForm" 
        path="/user" 
        scope="request">
  <forward name="success" path="/success.jsp" /> 
  <forward name="failure" path="/index.jsp" /> 
</action>
</action-mappings>
<controller>
  <set-property property="processorClass" 
value="org.springframework.web.struts.DelegatingRequestProcessor" /> 
</controller>
<message-resources parameter="org.tie.struts.ApplicationResources" /> 
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
  <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" /> 
</plug-in>
</struts-config>


web.xml中 filter配置
<filter>
  <filter-name>SetCharactorEncoding</filter-name> 
  <filter-class>org.tie.util.SetCharactorEncoding</filter-class> 
</filter>
<filter-mapping>
  <filter-name>SetCharactorEncoding</filter-name> 
  <url-pattern>/*</url-pattern> 
</filter-mapping>


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"
	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://localhost/regist"></property>
		<property name="username" value="root"></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>
                      <prop  key="hibernate.show_sql">true</prop>
			</props>
		</property>
		<property name="mappingResources">
			<list>
				<value>org/tie/vo/User.hbm.xml</value>
                           </list>
		</property>
     </bean>
	<bean id="userDAO" class="org.tie.dao.UserDAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>

	<bean id="userService" class="org.tie.service.UserService"
		abstract="false" lazy-init="default" autowire="default"
		dependency-check="default">
		<property name="userDAO">
			<ref local="userDAO" />
		</property>
	</bean>

	<bean name="/user" class="org.tie.struts.action.UserAction"
		abstract="false" lazy-init="default" autowire="default"
		dependency-check="default">
		<property name="userService">
			<ref local="userService" />
		</property>
	</bean>
	
	<bean id="UserDAO" class="org.tie.dao.UserDAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
</beans>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics