• 暑假项目总结(二)


    搭建SSH+JAP+MYSQL开发环境

    一、严格的三层包结构,加入相应包

    2.引入struts.xml,名字一定要写对否则报错。

    3.引入ssh.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"
    		xmlns:aop="http://www.springframework.org/schema/aop"
    		xmlns:context="http://www.springframework.org/schema/context" 
    		xmlns:tx="http://www.springframework.org/schema/tx"
    		xmlns:jee="http://www.springframework.org/schema/jee"
    		xsi:schemaLocation="
    			http://www.springframework.org/schema/aop 
    			http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    			http://www.springframework.org/schema/beans 
    			http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    			http://www.springframework.org/schema/context 
    			http://www.springframework.org/schema/context/spring-context-2.5.xsd
    			http://www.springframework.org/schema/tx
    			http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    			http://www.springframework.org/schema/jee 
    			http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
    		
    		<context:annotation-config/>	
    		<context:component-scan base-package="cn.edu"/>
    		<tx:annotation-driven transaction-manager="transactionManager"/>
    		
    		<bean id="mydataSource" class="org.apache.commons.dbcp.BasicDataSource">
    			<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    			<property name="url" value="jdbc:mysql://localhost:3306/music"/>
    			<property name="username" value="root"/>
    			<property name="password" value="pxj1989"/>
    		</bean>	
    		
    		<bean id="mysessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    			<property name="dataSource" ref="mydataSource"></property>
    			<property name="hibernateProperties">
    				<props>
    					<prop key="hibernate.dialect">
    					org.hibernate.dialect.MySQLDialect
    					</prop>
    					<prop key="hibernate.show_sql">false</prop>
    					<prop key="hibernate.format_sql">false</prop>
    				</props>
    			</property>
    			<property name="annotatedClasses">
    				<list>
    					<value>cn.edu.cqu.cqzy.entity.User</value>
    					<value>cn.edu.cqu.cqzy.entity.Category</value>
    					<value>cn.edu.cqu.cqzy.entity.CategoryRelation</value>
    					<value>cn.edu.cqu.cqzy.entity.Song</value>
    					<value>cn.edu.cqu.cqzy.entity.TempSong</value>
    					<value>cn.edu.cqu.cqzy.entity.SearchSong</value>
    					<value>cn.edu.cqu.cqzy.entity.Scroll</value>
    					<value>cn.edu.cqu.cqzy.entity.OnlineSum</value>
    					<value>cn.edu.seu.cqzy.domain.MapAudio</value>
    					<value>cn.edu.seu.cqzy.domain.MapPoints</value>
    				</list>
    			</property>
    		</bean>	
    		
    		
    		<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    			<property name="sessionFactory" ref="mysessionFactory"/>
    		</bean>
    </beans>
    

     4.修改web.xml,添加struts2过滤器及实例化spring容器

    <filter>
            <filter-name>struts2</filter-name>
            <filter-class>
                org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <!-- 指定spring容器配置文件位置, 利用Listener实例化spring容器 -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:ssh.xml</param-value>
        </context-param>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <!-- 为了支持scope="request|session" -->
        <listener>
            <listener-class>
                org.springframework.web.context.request.RequestContextListener</listener-class>
        </listener>

    4.合理分包,理清项目结构,struts.xml,ssh.xml也分割、引入

    struts中引入其它.xml

    <include file="struts-*.xml"></include>

    ssh中引入其他.xml

    <import resource="user_spring.xml" />  
  • 相关阅读:
    Java:字符分割
    Java 线程池:newFixedThreadPool
    人类有限的自制力是相当脆弱的
    Arcgis模型构建器案例教程while和for实现通用的循环迭代功能
    通用化全功能、可视化搭建式、扁平化流线型、无代码零基础、探索式启发法、案例式现场化的ArcGIS模型构建器教程教材培训
    Arcgis模型构建器案例教程——while循环递归查找所有相邻的要素
    广西崇左市各地建成区排名最小是大新县
    Arcgis地理处理工具案例教程——批量修改坐标系
    Arcgis模型构建器可视化编程案例教程添加要素个数到文件名,要素类是否为空,删除空白要素类数据文件,删除工作空间里的空白数据文件
    Arcgis地理处理工具案例教程——多边形图层的最小覆盖范围边界
  • 原文地址:https://www.cnblogs.com/pxjgood/p/3990847.html
Copyright © 2020-2023  润新知