zoukankan      html  css  js  c++  java
  • shh整合后web.xml、spring配置文件和struts.xml的内容

    1:web.xml

    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <web-app version="2.5"   
    3.     xmlns="http://java.sun.com/xml/ns/javaee"   
    4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
    6.     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
    7.     <!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring 提供的classpath:前缀指定从类路径下寻找-->  
    8.     <context-param>  
    9.         <param-name>contextConfigLocation</param-name>  
    10.         <param-value>classpath:beans.xml</param-value>  
    11.     </context-param>  
    12.     <!-- 对Spring容器进行实例化 -->  
    13.     <listener>  
    14.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    15.     </listener>  
    16.       
    17.     <!-- 启动struts2框架 -->  
    18.     <filter>  
    19.         <filter-name>struts2</filter-name>  
    20.         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
    21.     </filter>  
    22.     <filter-mapping>  
    23.         <filter-name>struts2</filter-name>  
    24.         <url-pattern>/*</url-pattern>  
    25.     </filter-mapping>  
    26.   <welcome-file-list>  
    27.     <welcome-file>index.jsp</welcome-file>  
    28.   </welcome-file-list>  
    29. </web-app>  

    2:spring配置文件:
    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <beans xmlns="http://www.springframework.org/schema/beans"  
    3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    4.        xmlns:aop="http://www.springframework.org/schema/aop"  
    5.        xmlns:context="http://www.springframework.org/schema/context"    
    6.        xmlns:tx="http://www.springframework.org/schema/tx"  
    7.        xsi:schemaLocation="  
    8.         http://www.springframework.org/schema/beans   
    9.         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
    10.         http://www.springframework.org/schema/aop   
    11.         http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
    12.         http://www.springframework.org/schema/context  
    13.         http://www.springframework.org/schema/context/spring-context-2.5.xsd  
    14.         http://www.springframework.org/schema/tx   
    15.         http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
    16.        <!-- 通过注解的方式将类交给spring管理 -->  
    17.        <!-- 是被@Component、@Service、@Controller、@Repository注解的类,都可以纳入spring容器的管理中 -->  
    18.        <context:component-scan base-package="cn.itcast"/>  
    19.          
    20.         <!-- 配置文件占位符 -->  
    21.         <!--<context:property-placeholder location="classpath:jdbc.properties"/>-->  
    22.         <!-- 配置数据源 -->  
    23.         <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  
    24.             <property name="driverClass" value="com.mysql.jdbc.Driver"/>  
    25.             <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/itcast?useUnicode=true&characterEncoding=UTF-8"/>  
    26.             <property name="user" value="root"/>  
    27.             <property name="password" value="123"/>  
    28.             <!-- 连接池启动时的初始值 -->  
    29.             <property name="initialPoolSize" value="1"/>  
    30.             <!-- 连接池中保留的最小连接数 -->  
    31.             <property name="minPoolSize" value="1"/>  
    32.             <!-- 连接池中保留的最大连接数 -->  
    33.             <property name="maxPoolSize" value="15"/>  
    34.             <!-- 最大空闲时间 ,60秒内未使用则丢弃。若为0则永不丢弃。Default:0-->  
    35.             <property name="maxIdleTime" value="60"/>  
    36.             <!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数,default:3 -->  
    37.             <property name="acquireIncrement" value="5"/>  
    38.             <!-- 每60秒检查所有连接池中的空闲连接。Default:0 -->  
    39.             <property name="idleConnectionTestPeriod" value="60"/>  
    40.         </bean>  
    41.        <!-- 用spring创建sessionFactory供hibernate用 -->  
    42.        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
    43.             <property name="dataSource" ref="dataSource" />  
    44.             <property name="mappingResources">  
    45.             <list>  
    46.                 <value>cn/itcast/bean/Employee.hbm.xml</value>  
    47.             </list>  
    48.             </property>  
    49.             <property name="hibernateProperties">  
    50.                 <value>  
    51.                     hibernate.dialect=org.hibernate.dialect.MySQL5Dialect  
    52.                     hibernate.hbm2ddl.auto=update  
    53.                     hibernate.show_sql=true  
    54.                     hibernate.format_sql=false  
    55.                 </value>  
    56.             </property>  
    57.         </bean>  
    58.         <!--   
    59.             hibernate.cache.use_second_level_cache=true  
    60.         hibernate.cache.use_query_cache=false  
    61.         hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider   
    62.      -->  
    63.           
    64.         <!-- 用spring创建sessionFactory供hibernate用 -->  
    65.         <!-- 基于注解的映射文件-->  
    66.         <!--  
    67.         <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
    68.             <property name="dataSource" ref="dataSource" />  
    69.             <property name="annotatedClasses">  
    70.                 <list>  
    71.                     <value>cn.itcast.bean.Employee</value>  
    72.                 </list>  
    73.             </property>  
    74.             <property name="hibernateProperties">  
    75.                 <value>  
    76.                     hibernate.dialect=org.hibernate.dialect.MySQL5Dialect  
    77.                     hibernate.hbm2ddl.auto=update  
    78.                     hibernate.show_sql=true  
    79.                     hibernate.format_sql=false  
    80.                 </value>  
    81.     </property>  
    82.         </bean>  
    83.         -->  
    84.         <!-- 用spring创建sessionFactory供hibernate用 -->  
    85.         <!-- 基于注解的映射文件-->  
    86.         <!--  
    87.         <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
    88.             <property name="dataSource" ref="dataSource" />  
    89.             <property name="packagesToScan" value="com.sdcncsi.entity.*" />  
    90.             <property name="hibernateProperties">  
    91.                 <value>  
    92.                     hibernate.dialect=org.hibernate.dialect.MySQL5Dialect  
    93.                     hibernate.hbm2ddl.auto=update  
    94.                     hibernate.show_sql=true  
    95.                     hibernate.format_sql=false  
    96.                 </value>  
    97.     </property>  
    98.         </bean>  
    99.         -->  
    100.           
    101.         <!-- 事务管理服务 -->  
    102.         <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
    103.             <property name="sessionFactory" ref="sessionFactory"/>              
    104.        </bean>  
    105.         <!-- 采用@Transaction注解方式使用事务 -->  
    106.         <tx:annotation-driven transaction-manager="txManager"/>  
    107.           
    108. </beans>  



    1.   

    ps:当使用注解的方式关于映射,则就不是写映射文件了;

    而在bean中用注解,下面举个例子:

    1. @SuppressWarnings("serial")  
    2. @Entity()  
    3. @Table(name="zft_check_login")  
    4. @Cache(usage = CacheConcurrencyStrategy.NONE)  
    5. public class CheckloginEntity implements Serializable{  
    6.       
    7.     private Long id;  
    8.     private Long staff_id;  
    9.     private Date latest_time;  
    10.     private Staff staff;  
    11.     private Set<Equipment> equipments;  
    12.       
    13.     @Id  
    14.     @GeneratedValue(strategy = GenerationType.AUTO)  
    15.     public Long getId() {  
    16.         return id;  
    17.     }  
    18.     public void setId(Long id) {  
    19.         this.id = id;  
    20.     }  
    21.     public Long getStaff_id() {  
    22.         return staff_id;  
    23.     }  
    24.     public void setStaff_id(Long staff_id) {  
    25.         this.staff_id = staff_id;  
    26.     }  
    27.     public Date getLatest_time() {  
    28.         return latest_time;  
    29.     }  
    30.     public void setLatest_time(Date latest_time) {  
    31.         this.latest_time = latest_time;  
    32.     }  
    33.     @OneToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE},fetch = FetchType.LAZY)  
    34.     @JoinColumn(name = "staff_id",insertable=false,updatable=false)  
    35.     public Staff getStaff() {  
    36.         return staff;  
    37.     }  
    38.     public void setStaff(Staff staff) {  
    39.         this.staff = staff;  
    40.     }  
    41.       
    42.     @OneToMany(fetch = FetchType.LAZY)  
    43.     @JoinColumn(name = "staff_id",referencedColumnName="staff_id",insertable=false,updatable=false)  
    44.     public Set<Equipment> getEquipments() {  
    45.         return equipments;  
    46.     }  
    47.     public void setEquipments(Set<Equipment> equipments) {  
    48.         this.equipments = equipments;  
    49.     }  
    50.       
    51.     @Transient  
    52.     public String getPhoneNums() throws Exception{  
    53.         return ReflectionUtils.fetchElementPropertyToString(equipments,"equipmentPhone",", ");  
    54.     }  
    55.       
    56.     @Transient  
    57.     public Long getMinutes() throws Exception{  
    58.         Date etime=new Date(System.currentTimeMillis());  
    59.         return (etime.getTime() - this.getLatest_time().getTime())/(60*1000);  
    60.     }  
    61. }  


    3:struts.xml

    1. <?xml version="1.0" encoding="UTF-8" ?>  
    2. <!DOCTYPE struts PUBLIC  
    3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
    4.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
    5. <struts>  
    6.     <!-- 更换掉struts2内部的对象创建工厂,action用spring创建 -->  
    7.     <constant name="struts.objectFactory" value="spring"/>  
    8.     <!-- 将struts的主题改成默认主题,防止其生成不必要的html代码 -->  
    9.     <constant name="struts.ui.theme" value="simple"/>  
    10.     <package name="employee" namespace="/employee" extends="struts-default">  
    11.         <!-- 因为action有spring创建,所以只需指定spring创建的action的对象的名称就行  -->  
    12.         <action name="list" class="employeeAction">  
    13.             <result name="list">/WEB-INF/page/employee.jsp</result>  
    14.         </action>  
    15.         <action name="manage_*" class="employeeManageAction" method="{1}">  
    16.             <result name="add">/WEB-INF/page/employeeAdd.jsp</result>  
    17.             <result name="message">/WEB-INF/page/message.jsp</result>  
    18.         </action>  
    19.     </package>  
    20. </struts> 
  • 相关阅读:
    重装系统之后应装软件
    中文乱码解决方案
    买电脑需要考虑的电脑配置
    JavaBean个人总结
    Servlet个人总结
    web.xml详解
    默认软件
    Eclipse导入项目
    Eclipse插件安装
    Tomcat详解
  • 原文地址:https://www.cnblogs.com/baobeiqi-e/p/9884788.html
Copyright © 2011-2022 走看看