首页 > 代码库 > 暑假项目总结(二)
暑假项目总结(二)
搭建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="http://www.mamicode.com/com.mysql.jdbc.Driver"/> <property name="url" value="http://www.mamicode.com/jdbc:mysql://localhost:3306/music"/> <property name="username" value="http://www.mamicode.com/root"/> <property name="password" value="http://www.mamicode.com/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" />
暑假项目总结(二)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。