- 1 数据库配置
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=mysql
- 2 log4j.xml
log4j.rootLogger=debug, stdout
log4j.logger.java.sql.Connection=info, stdout
log4j.logger.java.sql.Statement=debug, stdout
log4j.logger.java.sql.PreparedStatement=debug, stdout
log4j.logger.org.hibernate=error
log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.tool.hbm2ddl=debug
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss} %c:%L - %m%n
log4j.category.org.springframework = ON
- 3 pom.xml
<
project
xmlns
=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<
modelVersion
>
4.0.0
</
modelVersion
>
<
groupId
>
com.lin
</
groupId
>
<
artifactId
>
com.lin.ssh.demo
</
artifactId
>
<
version
>
0.0.1-SNAPSHOT
</
version
>
<
packaging
>
jar
</
packaging
>
<
properties
>
<
checkstyle.config.location
>
config/maven_checks.xml
</
checkstyle.config.location
>
<
spring.version
>
3.2.8.RELEASE
</
spring.version
>
<
struts2.version
>
2.3.16.1
</
struts2.version
>
<
hibernate.version
>
4.2.10.Final
</
hibernate.version
>
<
mybatis.version
>
3.2.6
</
mybatis.version
>
<
mysql.version
>
5.1.29
</
mysql.version
>
<
servlet-api.version
>
2.5
</
servlet-api.version
>
<
jsp-api.version
>
2.2
</
jsp-api.version
>
<
jstl.version
>
1.2
</
jstl.version
>
<
fastjson.version
>
1.1.39
</
fastjson.version
>
<
commons-dbcp2.version
>
2.0
</
commons-dbcp2.version
>
<
commons-pool2.version
>
2.2
</
commons-pool2.version
>
<
commons-logging.version
>
1.1.3
</
commons-logging.version
>
<
commons-io.version
>
1.3.2
</
commons-io.version
>
<
commons-lang3.version
>
3.3.1
</
commons-lang3.version
>
<
commons-fileupload.version
>
1.2.1
</
commons-fileupload.version
>
<
log4j.version
>
1.2.17
</
log4j.version
>
<
slf4j.version
>
1.7.6
</
slf4j.version
>
<
dom4j.version
>
1.6.1
</
dom4j.version
>
<
jfreechart.version
>
1.0.17
</
jfreechart.version
>
<
shiro.version
>
1.2.3
</
shiro.version
>
<
aspectjweaver.version
>
1.7.4
</
aspectjweaver.version
>
<
bonecp.version
>
0.8.0.RELEASE
</
bonecp.version
>
<
druid.version
>
1.0.6
</
druid.version
>
<
c3p0.version
>
0.9.2.1
</
c3p0.version
>
<
testng.version
>
6.8.8
</
testng.version
>
<
junit.version
>
4.11
</
junit.version
>
<
freemarker.version
>
2.3.20
</
freemarker.version
>
<
velocity.version
>
1.7
</
velocity.version
>
<
tapestry.version
>
5.3.7
</
tapestry.version
>
<
asm.version
>
4.2
</
asm.version
>
<
cglib.version
>
3.1
</
cglib.version
>
<!-- Plugin 的属性定义 -->
<
project.build.sourceEncoding
>
UTF-8
</
project.build.sourceEncoding
>
<
jdk.version
>
1.6
</
jdk.version
>
</
properties
>
<
name
>
com.lin.ssh.demo
</
name
>
<
url
>
http://maven.apache.org
</
url
>
<
dependencies
>
<!-- struts2 -->
<
dependency
>
<
groupId
>
org.apache.struts
</
groupId
>
<
artifactId
>
struts2-core
</
artifactId
>
<
version
>
${struts2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.struts
</
groupId
>
<
artifactId
>
struts2-spring-plugin
</
artifactId
>
<
version
>
${struts2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.struts
</
groupId
>
<
artifactId
>
struts2-json- plugin
</
artifactId
>
<
version
>
${struts2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.struts
</
groupId
>
<
artifactId
>
struts2-dwr- plugin
</
artifactId
>
<
version
>
${struts2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.struts
</
groupId
>
<
artifactId
>
struts2-rest-plugin
</
artifactId
>
<
version
>
${struts2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.struts
</
groupId
>
<
artifactId
>
struts2-javatemplates -plugin
</
artifactId
>
<
version
>
${struts2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.struts
</
groupId
>
<
artifactId
>
struts2-jfreechart -plugin
</
artifactId
>
<
version
>
${struts2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.struts
</
groupId
>
<
artifactId
>
struts2-convention-plugin
</
artifactId
>
<
version
>
${struts2.version}
</
version
>
</
dependency
>
<!-- hibernate -->
<
dependency
>
<
groupId
>
org.hibernate
</
groupId
>
<
artifactId
>
hibernate-core
</
artifactId
>
<
version
>
${hibernate.version}
</
version
>
<!-- 因为struts2 中也有 javassist,所以要排除 -->
<
exclusions
>
<
exclusion
>
<
groupId
>
javassist
</
groupId
>
<
artifactId
>
javassist
</
artifactId
>
</
exclusion
>
</
exclusions
>
</
dependency
>
<!-- mybaits -->
<
dependency
>
<
groupId
>
org.mybatis
</
groupId
>
<
artifactId
>
mybatis
</
artifactId
>
<
version
>
${mybatis.version}
</
version
>
</
dependency
>
<!-- JDBC驱动 -->
<
dependency
>
<
groupId
>
mysql
</
groupId
>
<
artifactId
>
mysql-connector-java
</
artifactId
>
<
version
>
${mysql.version}
</
version
>
</
dependency
>
<!-- spring相关 -->
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-core
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-beans
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-context
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-jdbc
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-web
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-webmvc
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-aop
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-tx
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-orm
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-context-support
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-jms
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.springframework.security
</
groupId
>
<
artifactId
>
spring-security-core
</
artifactId
>
<
version
>
3.2.4.RELEASE
</
version
>
</
dependency
>
<!-- 日志库 -->
<
dependency
>
<
groupId
>
commons-logging
</
groupId
>
<
artifactId
>
commons-logging
</
artifactId
>
<
version
>
${commons-logging.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
log4j
</
groupId
>
<
artifactId
>
log4j
</
artifactId
>
<
version
>
${log4j.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.slf4j
</
groupId
>
<
artifactId
>
slf4j-log4j12
</
artifactId
>
<
version
>
${slf4j.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.slf4j
</
groupId
>
<
artifactId
>
slf4j-api
</
artifactId
>
<
version
>
${slf4j.version}
</
version
>
</
dependency
>
<!-- 依赖的WEB类库 TOMCAT环境注释
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet- api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId> servlet-api </artifactId>
<version>${ servlet-api.version}</version>
</dependency>-->
<!--⑤ 依赖的测试类库-->
<
dependency
>
<
groupId
>
org.springframework
</
groupId
>
<
artifactId
>
spring-test
</
artifactId
>
<
version
>
${spring.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
junit
</
groupId
>
<
artifactId
>
junit
</
artifactId
>
<
version
>
${junit.version}
</
version
>
<
scope
>
test
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
org.testng
</
groupId
>
<
artifactId
>
testng
</
artifactId
>
<
version
>
${testng.version}
</
version
>
</
dependency
>
<!-- 连接池 -->
<
dependency
>
<
groupId
>
com.alibaba
</
groupId
>
<
artifactId
>
druid
</
artifactId
>
<
version
>
${druid.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
com.jolbox
</
groupId
>
<
artifactId
>
bonecp-spring
</
artifactId
>
<
version
>
${bonecp.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
com.jolbox
</
groupId
>
<
artifactId
>
bonecp
</
artifactId
>
<
version
>
${bonecp.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
com.mchange
</
groupId
>
<
artifactId
>
c3p0
</
artifactId
>
<
version
>
${c3p0.version}
</
version
>
</
dependency
>
<!-- shiro -->
<
dependency
>
<
groupId
>
org.apache.shiro
</
groupId
>
<
artifactId
>
shiro-core
</
artifactId
>
<
version
>
${shiro.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.shiro
</
groupId
>
<
artifactId
>
shiro-web
</
artifactId
>
<
version
>
${shiro.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.shiro
</
groupId
>
<
artifactId
>
shiro-spring
</
artifactId
>
<
version
>
${shiro.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.shiro
</
groupId
>
<
artifactId
>
shiro-ehcache
</
artifactId
>
<
version
>
${shiro.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.shiro
</
groupId
>
<
artifactId
>
shiro-aspectj
</
artifactId
>
<
version
>
${shiro.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.shiro
</
groupId
>
<
artifactId
>
shiro-quartz
</
artifactId
>
<
version
>
${shiro.version}
</
version
>
</
dependency
>
<!-- 模板技术 -->
<
dependency
>
<
groupId
>
org.freemarker
</
groupId
>
<
artifactId
>
freemarker
</
artifactId
>
<
version
>
${freemarker.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.velocity
</
groupId
>
<
artifactId
>
velocity
</
artifactId
>
<
version
>
${velocity.version}
</
version
>
</
dependency
>
<!-- 依赖的公共类库-->
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-dbcp2
</
artifactId
>
<
version
>
${commons-dbcp2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-pool2
</
artifactId
>
<
version
>
${commons-pool2.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-io
</
artifactId
>
<
version
>
${commons-io.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-lang3
</
artifactId
>
<
version
>
${commons-lang3.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-proxy
</
artifactId
>
<
version
>
1.0
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-jexl
</
artifactId
>
<
version
>
2.1.1
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-exec
</
artifactId
>
<
version
>
1.2
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-compress
</
artifactId
>
<
version
>
1.8
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-daemon
</
artifactId
>
<
version
>
1.0.9
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-math
</
artifactId
>
<
version
>
2.2
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-collections4
</
artifactId
>
<
version
>
4.0
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.kuali.commons
</
groupId
>
<
artifactId
>
commons-beanutils
</
artifactId
>
<
version
>
1.8.3-kuali-4
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
commons-dbutils
</
groupId
>
<
artifactId
>
commons-dbutils
</
artifactId
>
<
version
>
1.5
</
version
>
</
dependency
>
<!-- 缓存 -->
<
dependency
>
<
groupId
>
net.sf.ehcache
</
groupId
>
<
artifactId
>
ehcache
</
artifactId
>
<
version
>
2.8.1
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
com.googlecode.xmemcached
</
groupId
>
<
artifactId
>
xmemcached
</
artifactId
>
<
version
>
1.4.3
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
opensymphony
</
groupId
>
<
artifactId
>
oscache
</
artifactId
>
<
version
>
2.4.1
</
version
>
</
dependency
>
<!-- cglib 与asm -->
<
dependency
>
<
groupId
>
cglib
</
groupId
>
<
artifactId
>
cglib-nodep
</
artifactId
>
<
version
>
${cglib.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
cglib
</
groupId
>
<
artifactId
>
cglib
</
artifactId
>
<
version
>
${cglib.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.ow2.asm
</
groupId
>
<
artifactId
>
asm
</
artifactId
>
<
version
>
${asm.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.ow2.asm
</
groupId
>
<
artifactId
>
asm-commons
</
artifactId
>
<
version
>
${asm.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.ow2.asm
</
groupId
>
<
artifactId
>
asm-util
</
artifactId
>
<
version
>
${asm.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.ow2.asm
</
groupId
>
<
artifactId
>
asm-all
</
artifactId
>
<
version
>
${asm.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.ow2.asm
</
groupId
>
<
artifactId
>
asm-analysis
</
artifactId
>
<
version
>
${asm.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.ow2.asm
</
groupId
>
<
artifactId
>
asm-tree
</
artifactId
>
<
version
>
${asm.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.ow2.asm
</
groupId
>
<
artifactId
>
asm-debug-all
</
artifactId
>
<
version
>
${asm.version}
</
version
>
</
dependency
>
<!-- 其他 -->
<
dependency
>
<
groupId
>
com.alibaba
</
groupId
>
<
artifactId
>
fastjson
</
artifactId
>
<
version
>
${fastjson.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.aspectj
</
groupId
>
<
artifactId
>
aspectjweaver
</
artifactId
>
<
version
>
${aspectjweaver.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
dom4j
</
groupId
>
<
artifactId
>
dom4j
</
artifactId
>
<
version
>
${dom4j.version}
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
com.belerweb
</
groupId
>
<
artifactId
>
pinyin4j
</
artifactId
>
<
version
>
2.5.0
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
com.darwinsys
</
groupId
>
<
artifactId
>
hirondelle-date4j
</
artifactId
>
<
version
>
1.5.1
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
net.sourceforge.htmlunit
</
groupId
>
<
artifactId
>
htmlunit
</
artifactId
>
<
version
>
2.14
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
net.sourceforge.jwebunit
</
groupId
>
<
artifactId
>
jwebunit-htmlunit-plugin
</
artifactId
>
<
version
>
3.2
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
net.sourceforge.javacsv
</
groupId
>
<
artifactId
>
javacsv
</
artifactId
>
<
version
>
2.0
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.jsoup
</
groupId
>
<
artifactId
>
jsoup
</
artifactId
>
<
version
>
1.7.3
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.commons
</
groupId
>
<
artifactId
>
commons-email
</
artifactId
>
<
version
>
1.3.2
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
commons-beanutils
</
groupId
>
<
artifactId
>
commons-beanutils
</
artifactId
>
<
version
>
1.9.2
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
commons-collections
</
groupId
>
<
artifactId
>
commons-collections
</
artifactId
>
<
version
>
3.2.1
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
commons-configuration
</
groupId
>
<
artifactId
>
commons-configuration
</
artifactId
>
<
version
>
1.10
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
commons-dbcp
</
groupId
>
<
artifactId
>
commons-dbcp
</
artifactId
>
<
version
>
1.4
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
commons-fileupload
</
groupId
>
<
artifactId
>
commons-fileupload
</
artifactId
>
<
version
>
1.3.1
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.httpcomponents
</
groupId
>
<
artifactId
>
httpclient
</
artifactId
>
<
version
>
4.3.4
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
commons-validator
</
groupId
>
<
artifactId
>
commons-validator
</
artifactId
>
<
version
>
1.4.0
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
joda-time
</
groupId
>
<
artifactId
>
joda-time
</
artifactId
>
<
version
>
2.2
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
javax.activation
</
groupId
>
<
artifactId
>
activation
</
artifactId
>
<
version
>
1.0.2
</
version
>
<
scope
>
provided
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
javax.xml
</
groupId
>
<
artifactId
>
jaxrpc-api
</
artifactId
>
<
version
>
1.1
</
version
>
<
scope
>
provided
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
javax.mail
</
groupId
>
<
artifactId
>
mail
</
artifactId
>
<
version
>
1.3.1
</
version
>
<
scope
>
provided
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
javax.xml
</
groupId
>
<
artifactId
>
namespace
</
artifactId
>
<
version
>
1.0.1
</
version
>
<
scope
>
provided
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
xerces
</
groupId
>
<
artifactId
>
xmlParserAPIs
</
artifactId
>
<
version
>
2.6.2
</
version
>
<
scope
>
provided
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
xml-apis
</
groupId
>
<
artifactId
>
xml-apis
</
artifactId
>
<
version
>
1.4.01
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
org.apache.openejb
</
groupId
>
<
artifactId
>
javaee-api
</
artifactId
>
<
version
>
5.0-1
</
version
>
<
scope
>
provided
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
javax.faces
</
groupId
>
<
artifactId
>
jsf-api
</
artifactId
>
<
version
>
1.2_04
</
version
>
<
scope
>
provided
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
javax.servlet
</
groupId
>
<
artifactId
>
jstl
</
artifactId
>
<
version
>
1.2
</
version
>
<
scope
>
compile
</
scope
>
</
dependency
>
<!--
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
-->
<
dependency
>
<
groupId
>
javax.faces
</
groupId
>
<
artifactId
>
jsf-impl
</
artifactId
>
<
version
>
1.2_04
</
version
>
<
scope
>
provided
</
scope
>
</
dependency
>
</
dependencies
>
</
project
>
- 4 applicationContext.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:tx
=
"http://www.springframework.org/schema/tx"
xmlns:aop
=
"http://www.springframework.org/schema/aop"
xmlns:context
=
"http://www.springframework.org/schema/context"
xsi:schemaLocation
=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
default-autowire
=
"byName"
>
<
context:property-placeholder
location
=
"classpath*:conf/jdbc.properties"
/>
<
context:component-scan
base-package
=
"com.lin.ssh.demo.dao"
/>
<
context:component-scan
base-package
=
"com.lin.ssh.demo.service"
/>
<
context:component-scan
base-package
=
"com.lin.ssh.demo.service.impl"
/>
<!-- 配置系统的数据源 -->
<
bean
id
=
"dataSource"
class
=
"com.alibaba.druid.pool.DruidDataSource"
init-method
=
"init"
destroy-method
=
"close"
>
<
property
name
=
"driverClassName"
value
=
"${jdbc.driver}"
/>
<
property
name
=
"url"
value
=
"${jdbc.url}"
/>
<
property
name
=
"username"
value
=
"${jdbc.username}"
/>
<
property
name
=
"password"
value
=
"${jdbc.password}"
/>
<
property
name
=
"filters"
value
=
"stat"
/>
<
property
name
=
"maxActive"
value
=
"10"
/>
<
property
name
=
"initialSize"
value
=
"1"
/>
<
property
name
=
"maxWait"
value
=
"60000"
/>
<
property
name
=
"minIdle"
value
=
"1"
/>
<
property
name
=
"timeBetweenEvictionRunsMillis"
value
=
"60000"
/>
<
property
name
=
"minEvictableIdleTimeMillis"
value
=
"300000"
/>
<
property
name
=
"validationQuery"
value
=
"SELECT 'x'"
/>
<
property
name
=
"testWhileIdle"
value
=
"true"
/>
<
property
name
=
"testOnBorrow"
value
=
"false"
/>
<
property
name
=
"testOnReturn"
value
=
"false"
/>
<
property
name
=
"poolPreparedStatements"
value
=
"true"
/>
<
property
name
=
"maxPoolPreparedStatementPerConnectionSize"
value
=
"50"
/>
<
property
name
=
"maxOpenPreparedStatements"
value
=
"100"
/>
</
bean
>
<!-- 配置hibernate session工厂 -->
<
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.MySQL5InnoDBDialect
</
prop
>
<
prop
key
=
"hibernate.current_session_context_class"
>
org.springframework.orm.hibernate4.SpringSessionContext
</
prop
>
<
prop
key
=
"hibernate.show_sql"
>
true
</
prop
>
<
prop
key
=
"hibernate.format_sql"
>
true
</
prop
>
<
prop
key
=
"hibernate.hbm2ddl.auto"
>
update
</
prop
>
</
props
>
</
property
>
<!-- 自动扫描注解方式配置的 hibernate类文件 -->
<
property
name
=
"packagesToScan"
>
<
list
>
<
value
>
com.lin.ssh.demo.model
</
value
>
</
list
>
</
property
>
<!-- 自动扫描hbm方式配置的hibernate 文件和.hbm文件 -->
<!--
<property name="mappingDirectoryLocations"> <list>
<value>classpath:sy/ hbm</value> </list> </property>
-->
</
bean
>
<
bean
id
=
"transactionManager"
class
=
"org.springframework.orm.hibernate4.HibernateTransactionManager"
>
<
property
name
=
"sessionFactory"
ref
=
"sessionFactory"
/>
</
bean
>
<
tx:advice
id
=
"txAdvice"
transaction-manager
=
"transactionManager"
>
<
tx:attributes
>
<
tx:method
name
=
"select*"
read-only
=
"true"
/>
<
tx:method
name
=
"get*"
read-only
=
"true"
/>
<
tx:method
name
=
"load*"
read-only
=
"true"
/>
<
tx:method
name
=
"find*"
read-only
=
"true"
/>
<
tx:method
name
=
"query*"
read-only
=
"true"
/>
<
tx:method
name
=
"read*"
read-only
=
"true"
/>
<
tx:method
name
=
"sync*"
/>
<
tx:method
name
=
"*"
propagation
=
"REQUIRED"
rollback-for
=
"Exception"
/>
</
tx:attributes
>
</
tx:advice
>
<
aop:config
proxy-target-class
=
"true"
>
<
aop:pointcut
expression
=
"this(com.lin.ssh.demo.service.IBaseService)"
id
=
"transactionPointcut"
/>
<
aop:advisor
advice-ref
=
"txAdvice"
pointcut-ref
=
"transactionPointcut"
/>
</
aop:config
>
</
beans
>
- 5 Struts2配置
<?
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
>
<!-- 开发模式 -->
<
constant
name
=
"struts.devMode"
value
=
"true"
/>
<!-- Web运用编码 -->
<
constant
name
=
"struts.i18n.encoding"
value
=
"UTF-8"
/>
<!--搜索视图资源的路径-->
<
constant
name
=
"struts.convention.result.path"
value
=
"/pages"
/>
<!--搜索Action资源的包路径-->
<
constant
name
=
"struts.convention.package.locators"
value
=
"web,action"
/>
<!-- Action扩展名 -->
<
constant
name
=
"struts.action.extension"
value
=
"action,do,htm"
/>
<!-- Action后缀名 -->
<
constant
name
=
"struts.convention.action.suffix"
value
=
"Action"
/>
<!-- 指定由spring负责action的创建 -->
<
constant
name
=
"struts.objectFactory"
value
=
"spring"
/>
<!--
指定spring框架的装配模式,装配方式有: name, type, auto, and constructor (name
是默认装配模式)
-->
<
constant
name
=
"struts.objectFactory.spring.autoWire"
value
=
"name"
/>
<!-- 该属性指定整合spring时,是否对bean进行缓存,值为true or false,默认为true -->
<
constant
name
=
"struts.objectFactory.spring.useClassCache"
value
=
"true"
/>
<!-- struts配置文件修改后,是否重新加载,开发模式下用 true,生产环境改成false -->
<
constant
name
=
"struts.configuration.xml.reload"
value
=
"true"
/>
<
constant
name
=
"struts.serve.static.browserCache"
value
=
"false"
/>
<!-- 该属性指定处理 MIME-type multipart/form-data,文件上传 -->
<
constant
name
=
"struts.multipart.parser"
value
=
"cos"
/>
<
constant
name
=
"struts.multipart.parser"
value
=
"pell"
/>
<
constant
name
=
"struts.multipart.parser"
value
=
"jakarta"
/>
<!-- 指定上传文件时的临时目录,默认使用 javax.servlet.context.tempdir -->
<
constant
name
=
"struts.multipart.saveDir"
value
=
"/tmpuploadfiles"
/>
<!-- 配置文件上传大小上限,现今最大上限为50MB -->
<
constant
name
=
"struts.multipart.maxSize"
value
=
"500971520"
/>
<!-- 被 FilterDispatcher使用指定浏览器是否缓存静态内容,测试阶段设置为false,发布阶段设置为true. -->
<
constant
name
=
"struts.serve.static.browserCache"
value
=
"true"
/>
<!-- 设置是否支持动态方法调用,true为支持,false不支持. -->
<
constant
name
=
"struts.enable.DynamicMethodInvocation"
value
=
"true"
/>
<!-- 设置是否可以在action中使用斜线,默认为false不可以,想使用需设置为true. -->
<
constant
name
=
"struts.enable.SlashesInActionNames"
value
=
"true"
/>
<!-- 是否允许使用表达式语法,默认为true. -->
<
constant
name
=
"struts.tag.altSyntax"
value
=
"true"
/>
<!-- 设置是否每次请求,都重新加载资源文件,默认值为false. -->
<
constant
name
=
"struts.i18n.reload"
value
=
"false"
/>
<
package
name
=
"demoPackage"
extends
=
"struts-default"
namespace
=
"/demo"
>
<
global-results
>
<
result
name
=
"success"
>
/pages/index.jsp
</
result
>
<
result
name
=
"login"
>
/index.jsp
</
result
>
<
result
name
=
"error"
>
/error.jsp
</
result
>
</
global-results
>
</
package
>
</
struts
>
- 6 web.xml
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
web-app
version
=
"2.5"
xmlns
=
"http://java.sun.com/xml/ns/javaee"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
=
"http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
<
context-param
>
<
param-name
>
log4jConfigLocation
</
param-name
>
<
param-value
>
classpath:conf/log4j.properties
</
param-value
>
</
context-param
>
<
context-param
>
<
param-name
>
contextConfigLocation
</
param-name
>
<
param-value
>
classpath:conf/applictionContext.xml
</
param-value
>
</
context-param
>
<
listener
>
<
listener-class
>
org.springframework.web.util.Log4jConfigListener
</
listener-class
>
</
listener
>
<
listener
>
<
listener-class
>
org.springframework.web.context.ContextLoaderListener
</
listener-class
>
</
listener
>
<
listener
>
<
listener-class
>
org.springframework.web.context.request.RequestContextListener
</
listener-class
>
</
listener
>
<
listener
>
<
listener-class
>
org.springframework.web.util.IntrospectorCleanupListener
</
listener-class
>
</
listener
>
<
filter
>
<
filter-name
>
encodingFilter
</
filter-name
>
<
filter-class
>
org.springframework.web.filter.CharacterEncodingFilter
</
filter-class
>
<
init-param
>
<
param-name
>
encoding
</
param-name
>
<
param-value
>
UTF-8
</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
encodingFilter
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<
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
>
<
welcome-file-list
>
<
welcome-file
>
login.html
</
welcome-file
>
</
welcome-file-list
>
</
web-app
>
- 7 UserAction
package com.lin.ssh.demo.web.action;
import java.util.List;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.lin.ssh.demo.model.UserBean;
import com.lin.ssh.demo.service.IUserService;
import com.opensymphony.xwork2.ActionSupport;
//@ParentPackage("demoPackage")
@Namespace("/demo")
@Component
@Scope("prototype")
@Action("userAction")
public class UserAction extends ActionSupport {
private IUserService userService;
private UserBean user;
private List<UserBean> userList;
/**
* http://127.0.0.1:8080/ssh/demo/regUser!index.do
* @return
*/
@Action(value = "regUser", results = {
@Result(name = "success", location = "/pages/login.jsp"),
@Result(name = "input", location = "/pages/error.jsp") })
public String index() {
System.out.println("----reg page----");
return SUCCESS;
}
@Action(value = "saveUser", results = {
@Result(name = "list", location = "/pages/list.jsp"),
@Result(name = "input", location = "/pages/error.jsp"),
@Result(name = "success", location = "/pages/index.jsp")})
public String save() {
System.out.println("----save----");
System.out.println("===="+user);
try {
userService.saveUser(user);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
/**
* http://127.0.0.1:8080/ssh/demo/userAction!list.do
*/
public void list() {
System.out.println("----list----");
System.out.println(user);
try {
userList = userService.queryUserAll();
System.out.println("userList ==" + userList.get(0).toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// return SUCCESS;
}
public List<UserBean> getUserList() {
return userList;
}
public void setUserList(List<UserBean> userList) {
this.userList = userList;
}
public IUserService getUserService() {
return userService;
}
@Autowired
public void setUserService(IUserService userService) {
this.userService = userService;
}
public UserBean getUser() {
return user;
}
public void setUser(UserBean user) {
this.user = user;
}
}
import java.util.List;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.lin.ssh.demo.model.UserBean;
import com.lin.ssh.demo.service.IUserService;
import com.opensymphony.xwork2.ActionSupport;
//@ParentPackage("demoPackage")
@Namespace("/demo")
@Component
@Scope("prototype")
@Action("userAction")
public class UserAction extends ActionSupport {
private IUserService userService;
private UserBean user;
private List<UserBean> userList;
/**
* http://127.0.0.1:8080/ssh/demo/regUser!index.do
* @return
*/
@Action(value = "regUser", results = {
@Result(name = "success", location = "/pages/login.jsp"),
@Result(name = "input", location = "/pages/error.jsp") })
public String index() {
System.out.println("----reg page----");
return SUCCESS;
}
@Action(value = "saveUser", results = {
@Result(name = "list", location = "/pages/list.jsp"),
@Result(name = "input", location = "/pages/error.jsp"),
@Result(name = "success", location = "/pages/index.jsp")})
public String save() {
System.out.println("----save----");
System.out.println("===="+user);
try {
userService.saveUser(user);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
/**
* http://127.0.0.1:8080/ssh/demo/userAction!list.do
*/
public void list() {
System.out.println("----list----");
System.out.println(user);
try {
userList = userService.queryUserAll();
System.out.println("userList ==" + userList.get(0).toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// return SUCCESS;
}
public List<UserBean> getUserList() {
return userList;
}
public void setUserList(List<UserBean> userList) {
this.userList = userList;
}
public IUserService getUserService() {
return userService;
}
@Autowired
public void setUserService(IUserService userService) {
this.userService = userService;
}
public UserBean getUser() {
return user;
}
public void setUser(UserBean user) {
this.user = user;
}
}
- 8 UserDAO
package com.lin.ssh.demo.dao;
import java.util.List;
import com.lin.ssh.demo.model.UserBean;
public interface IUserDAO {
public void save(UserBean entity) throws Exception;
public List<UserBean> find(Class<UserBean> clazz) throws Exception;
}
import java.util.List;
import com.lin.ssh.demo.model.UserBean;
public interface IUserDAO {
public void save(UserBean entity) throws Exception;
public List<UserBean> find(Class<UserBean> clazz) throws Exception;
}
package com.lin.ssh.demo.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.lin.ssh.demo.model.UserBean;
@Repository("userDao")
public class UserDAO extends DaoSupport implements IUserDAO {
/**
* 保存对象
*
* @param entity
* @throws Exception
*/
@Override
public void save(UserBean entity) throws Exception {
super.save(entity);
}
@Override
public List<UserBean> find(Class clazz) throws Exception {
return super.findAll(clazz);
}
}
import java.util.List;
import org.springframework.stereotype.Repository;
import com.lin.ssh.demo.model.UserBean;
@Repository("userDao")
public class UserDAO extends DaoSupport implements IUserDAO {
/**
* 保存对象
*
* @param entity
* @throws Exception
*/
@Override
public void save(UserBean entity) throws Exception {
super.save(entity);
}
@Override
public List<UserBean> find(Class clazz) throws Exception {
return super.findAll(clazz);
}
}
package com.lin.ssh.demo.dao;
import static org.hibernate.criterion.Restrictions.eq;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* @author linhz
*
*/
public class DaoSupport {
private SessionFactory sessionFactory;
@Autowired
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
protected Session getSession() {
return sessionFactory.getCurrentSession();
}
protected void save(Object obj) {
getSession().save(obj);
}
protected <T> T get(Class<T> clazz, int id) {
return (T) getSession().get(clazz, id);
}
protected <T> List<T> findByProperty(Class<T> clazz, String property,
Object value) {
return getSession().createCriteria(clazz).add(eq(property, value))
.list();
}
protected <T> List<T> findAll(Class<T> clazz) {
return getSession().createCriteria(clazz).list();
}
protected void update(Object obj) {
getSession().update(obj);
}
protected void delete(Class clazz, int id) {
getSession().delete(get(clazz, id));
}
protected void delete(Object obj) {
getSession().delete(obj);
}
}
- 9 Model POJO
package
com.lin.ssh.demo.model;
import
javax.persistence.Column;
import
javax.persistence.Entity;
import
javax.persistence.GeneratedValue;
import
javax.persistence.Id;
import
javax.persistence.Table;
import
static
javax.persistence.GenerationType.
IDENTITY
;
@Entity
@Table(name = "tb_demo", schema = "test")
public
class
UserBean
implements
java.io.Serializable {
@Id
@GeneratedValue
(strategy =
IDENTITY
)
@Column
(name =
"id"
, unique =
true
, nullable =
false
)
private
Long
id
;
@Column
(name =
"username"
, length = 32)
private
String
username
;
@Column
(name =
"password"
, length = 16)
private
String
password
;
public
UserBean() {
}
public
UserBean(String username, String password) {
this
.
username
= username;
this
.
password
= password;
}
public
Long getId() {
return
id
;
}
public
void
setId(Long id) {
this
.
id
= id;
}
public
String getUsername() {
return
username
;
}
public
void
setUsername(String username) {
this
.
username
= username;
}
public
String getPassword() {
return
password
;
}
public
void
setPassword(String password) {
this
.
password
= password;
}
@Override
public
String toString() {
return
"User{"
+
"id="
+
id
+
", username='"
+
username
+
'\''
+
", password='"
+
password
+
'\''
+
'}'
;
}
}
- 10 UserService
package
com.lin.ssh.demo.service;
public
interface
IBaseService {
}
package
com.lin.ssh.demo.service;
import
java.util.List;
import
com.lin.ssh.demo.model.UserBean;
public
interface
IUserService
extends
IBaseService {
public
void
saveUser(UserBean user)
throws
Exception;
public
List<UserBean> queryUserAll()
throws
Exception;
}
package com.lin.ssh.demo.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.lin.ssh.demo.dao.UserDAO;
import com.lin.ssh.demo.model.UserBean;
import com.lin.ssh.demo.service.IUserService;
@Service("userService")
public class UserServiceImpl implements IUserService {
@Resource
private UserDAO userDao;
public void saveUser(UserBean user) throws Exception {
userDao.save(user);
}
public List<UserBean> queryUserAll() throws Exception {
return userDao.find(UserBean.class);
}
}
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.lin.ssh.demo.dao.UserDAO;
import com.lin.ssh.demo.model.UserBean;
import com.lin.ssh.demo.service.IUserService;
@Service("userService")
public class UserServiceImpl implements IUserService {
@Resource
private UserDAO userDao;
public void saveUser(UserBean user) throws Exception {
userDao.save(user);
}
public List<UserBean> queryUserAll() throws Exception {
return userDao.find(UserBean.class);
}
}
- 11 测试页面 index.jsp
<%@
page
contentType
=
"text/html;charset=UTF-8"
language
=
"java"
%>
<%
String path = request.getContextPath();
String contextPath = request.getScheme() +
"://"
+ request.getServerName() +
":"
+ request.getServerPort()
+ path +
"/"
;
%>
<
html
>
<
head
>
<
title
></
title
>
</
head
>
<
body
>
<
form
action
=
"
<%=
contextPath
%>
/demo/saveUser!save.action"
method
=
"get"
>
<
br
>
用户名:
<
input
type
=
"text"
name
=
"user.username"
/>
<
br
>
密码:
<
input
type
=
"text"
name
=
"user.password"
/>
<
input
type
=
"submit"
name
=
"保存"
/>
</
form
>
</
body
>
</
html
>
- 12 SQL语句脚本
use test ;
CREATE TABLE `tb_demo` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`username` varchar(32) DEFAULT NULL,
`password` varchar(16) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8
CREATE TABLE `tb_demo` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`username` varchar(32) DEFAULT NULL,
`password` varchar(16) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8
- 13 测试
webcontent部署为:ssh
访问地址:
http://127.0.0.1:8080/ssh/demo/regUser!index.do
数据正常插入