1.新建idea项目
2.配置open model setting
3.Modules > sources 改变目录结构
1)新建resources并点击Resouces
2)WEB-INF下新建classes和lib文件
3)修改Paths中的Compiler output的路径为新建的classes路径
4)保存修改
4.配置tomcat
1)点击配置tomcat
2)点击左上角的加号
3)选择tomcat > local(若没有点击最下面会出现给选项)
4)修改内部的部分配置
5.配置ssh框架
1)导入需要使用的jar包
C3p0数据库连接池
Hibernate
Spring
Struts
配置各个文件
1.Web.xml
文件文档约束
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>
引入Spring
<!-- spring 配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
引入struts
<!-- struts配置 -->
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
欢迎界面
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
2.Struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- 开发模式下使用,这样可以打印出更详细的错误信息 产品发布时改为false 发布时不需要打印错误信息-->
<constant name="struts.devMode" value="true"></constant>
<!--导入外部的struts文件-->
<!--<include file="com/lyzyxy/jxjy/admin/conf/admin-struts.xml" />-->
<package name="test" namespace="/test" extends="json-default">
<action name="test" class="testAction">
<result name="success">/WEB-INF/jsp/test.jsp</result>
</action>
</package>
</struts>
3.beans.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 2.加载外部配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 3.配置数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 配置连接池属性-->
<property name="driverClass" value="${datasource.driverClassName}"/>
<property name="jdbcUrl" value="${datasource.url}"/>
<property name="user" value="${datasource.username}"/>
<property name="password" value="${datasource.password}"/>
<!-- 配置C3p0属性 -->
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
<!-- 关闭链接后不自动Commit -->
<property name="autoCommitOnClose" value="false"/>
<!-- 获取链接的等待时间 -->
<property name="checkoutTimeout" value="${c3p0.checkOutTime}" />
<!-- 获取链接重试次数 -->
<property name="acquireRetryAttempts" value="${c3p0.acquireIncrement}"/>
</bean>
<!-- 4.配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
<property name="mappingLocations">
<list>
<!-- .hbm.xml文件的路径 -->
<value>classpath:mapping/*.hbm.xml</value>
</list>
</property>
</bean>
<!-- 5.配置声明式事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 6.配置事务通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true" propagation="SUPPORTS" />
<tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="list*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" rollback-for="Throwable"/>
</tx:attributes>
</tx:advice>
<!-- aop配置被事务控制的类 -->
<aop:config>
<!-- 修改expression为 自己的位置-->
<aop:pointcut id="serviceOperation" expression="execution(* sshtest..*.service.impl.*.*(..) )"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>
</aop:config>
<!--<bean name="baseDao" abstract="true" >-->
<!--<property name="sessionFactory" ref="sessionFactory"/>-->
<!--</bean>-->
<!-- 自动扫描base package 如果发现 @Controller 注入 -->
<context:component-scan base-package="sshtest" />
<!--添加dao-->
<!--<import resource="classpath:com/lyzyxy/jxjy/*/conf/*-spring.xml"/>-->
</beans>
4.Struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- 开发模式下使用,这样可以打印出更详细的错误信息 产品发布时改为false 发布时不需要打印错误信息-->
<constant name="struts.devMode" value="true"></constant>
<!--导入外部的struts文件-->
<!--<include file="com/lyzyxy/jxjy/admin/conf/admin-struts.xml" />-->
<package name="test" namespace="/test" extends="json-default">
<action name="test" class="testAction">
<result name="success">/WEB-INF/jsp/test.jsp</result>
</action>
</package>
</struts>
6.log4j.properties
### set log levels ###
log4j.rootLogger = debug,stdout,D,E
### 输出到控制台 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 输出到日志文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = src/logs/log.log
log4j.appender.D.Append = true
## 输出DEBUG级别以上的日志###
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 保存异常信息到单独文件 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
## 异常日志文件名
log4j.appender.E.File = src/logs/error.log
log4j.appender.E.Append = true
## 只输出ERROR级别以上的日志!!!
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.logger.com.lyzyxy=debug
7.Jdbc.propoties
datasource.driverClassName=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://localhost:3306/lyzyxy?useUnicode=true&characterEncoding=UTF8
datasource.username=root
datasource.password=1240845161
c3p0.acquireIncrement=3
c3p0.initialPoolSize=3
c3p0.idleConnectionTestPeriod=60
c3p0.minPoolSize=5
c3p0.maxPoolSize=100
c3p0.maxStatements=100
c3p0.numHelperThreads=10
c3p0.maxIdleTime=60
c3p0.checkOutTime=3000