`
gstarwd
  • 浏览: 1525158 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Struts+Spring+Hibernate精简配制【文件】

    博客分类:
  • SSH
阅读更多

1.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
    xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    
<context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>/WEB-INF/applicationContext*.xml</param-value>
    
</context-param>
    
<listener>
        
<listener-class>
            org.springframework.web.context.ContextLoaderListener
        
</listener-class>
    
</listener>

    
<servlet>
        
<servlet-name>action</servlet-name>
        
<servlet-class>
            org.apache.struts.action.ActionServlet
        
</servlet-class>
        
<init-param>
            
<param-name>config</param-name>
            
<param-value>
                /WEB-INF/struts-config.xml,/WEB-INF/struts-config-form.xml,/WEB-INF/struts-config-action.xml
            
</param-value>
        
</init-param>
        
<init-param>
            
<param-name>debug</param-name>
            
<param-value>3</param-value>
        
</init-param>
        
<init-param>
            
<param-name>detail</param-name>
            
<param-value>3</param-value>
        
</init-param>
        
<load-on-startup>0</load-on-startup>
    
</servlet>
    
<servlet-mapping>
        
<servlet-name>action</servlet-name>
        
<url-pattern>*.do</url-pattern>
    
</servlet-mapping>
    
<session-config>
        
<session-timeout>120</session-timeout>
    
</session-config>

    
<!-- The Usual Welcome File List -->
    
<welcome-file-list>
        
<welcome-file>login.jsp</welcome-file>
    
</welcome-file-list>

    
<!-- Tag Library Descriptors-->
    
<jsp-config>
        
<taglib>
            
<taglib-uri>/WEB-INF/tld/struts-bean.tld</taglib-uri>
            
<taglib-location>
                /WEB-INF/tld/struts-bean.tld
            
</taglib-location>
        
</taglib>
        
<taglib>
            
<taglib-uri>/WEB-INF/tld/struts-html.tld</taglib-uri>
            
<taglib-location>
                /WEB-INF/tld/struts-html.tld
            
</taglib-location>
        
</taglib>
        
<taglib>
            
<taglib-uri>/WEB-INF/tld/struts-logic.tld</taglib-uri>
            
<taglib-location>
                /WEB-INF/tld/struts-logic.tld
            
</taglib-location>
        
</taglib>
        
<taglib>
            
<taglib-uri>/WEB-INF/tld/struts-nested.tld</taglib-uri>
            
<taglib-location>
                /WEB-INF/tld/struts-nested.tld
            
</taglib-location>
        
</taglib>
        
<taglib>
            
<taglib-uri>/WEB-INF/tld/struts-template.tld</taglib-uri>
            
<taglib-location>
                /WEB-INF/tld/struts-template.tld
            
</taglib-location>
        
</taglib>
        
<taglib>
            
<taglib-uri>/WEB-INF/tld/struts-tiles.tld</taglib-uri>
            
<taglib-location>
                /WEB-INF/tld/struts-tiles.tld
            
</taglib-location>
        
</taglib>
    
</jsp-config>
</web-app>

2.applicationContext-persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd"
>
<beans>

    
<!--  配置数据源 -->
    
<bean id="dataSource"
        class
="org.apache.commons.dbcp.BasicDataSource"
        destroy-method
="close">
        
<property name="driverClassName">
            
<value>oracle.jdbc.driver.OracleDriver</value>
        
</property>
        
<property name="url">
            
<value>jdbc:oracle:thin:@localhost:1521:ora9i</value>
        
</property>
        
<property name="username">
            
<value>tom</value>
        
</property>
        
<property name="password">
            
<value>tom</value>
        
</property>
    
</bean>

    
<!-- 配置Hibernate -->
    
<bean id="sessionFactory"
        class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
<property name="dataSource">
            
<ref local="dataSource" />
        
</property>
        
<property name="mappingResources">
            
<list>
                
<value>com/example/entity/User.hbm.xml</value>
            
</list>
        
</property>
        
<property name="hibernateProperties">
            
<props>
                
<prop key="hibernate.dialect">
                    org.hibernate.dialect.Oracle9Dialect
                
</prop>
                
<prop key="hibernate.show_sql">true</prop>
            
</props>
        
</property>
    
</bean>

    
<!-- 配置事务 -->
    
<bean id="transactionManager"
        class
="org.springframework.orm.hibernate3.HibernateTransactionManager">
        
<property name="sessionFactory">
            
<ref local="sessionFactory" />
        
</property>
    
</bean>

    
<bean id="transactionInterceptor"
        class
="org.springframework.transaction.interceptor.TransactionInterceptor">
        
<property name="transactionManager" ref="transactionManager" />
        
<property name="transactionAttributes">
            
<props>
                
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                
<prop key="save*">PROPAGATION_REQUIRED</prop>
                
<prop key="update*">PROPAGATION_REQUIRED</prop>
                
<prop key="delete*">PROPAGATION_REQUIRED</prop>
            
</props>
        
</property>
    
</bean>

    
<bean id="transactionProxyCreator"
        class
="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        
<property name="proxyTargetClass" >
               
<value>true</value>
          
</property>
        
<property name="beanNames">
            
<list>
                
<value>*Service</value>
            
</list>
        
</property>
        
<property name="interceptorNames">
            
<list>
                
<value>transactionInterceptor</value>
            
</list>
        
</property>
    
</bean>

</beans>

3.applicationContext-action.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>

    
<!-- example -->
    
<bean name="/login" class="com.example.actions.LoginAction">
        
<property name="userService">
            
<ref bean="userService" />
        
</property>
    
</bean>

</beans>

4.applicationContext-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>

    
<!-- example -->
    
<bean id="userService"
        class
="com.example.service.UserService">
        
<property name="userDAO">
            
<ref bean="userDAO" />
        
</property>
    
</bean>
    
</beans>

5.applicationContext-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>

    
<!-- example -->
    
<bean id="userDAO" class="com.example.dao.UserDAO">
        
<property name="sessionFactory">
            
<ref bean="sessionFactory" />
        
</property>
    
</bean>
    

</beans>

6.struts-config.xml

相关推荐

Global site tag (gtag.js) - Google Analytics