idea创建maven+springmvc+mybatis+jetty项目

1、首先使用idea创建一个maven项目

2、接着配置pom.xml,以下为我的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
< 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/maven-v4_0_0.xsd">
   < modelVersion >4.0.0</ modelVersion >
   < groupId >com.liuwenjian</ groupId >
   < artifactId >angular-demo</ artifactId >
   < packaging >war</ packaging >
   < version >1.0-SNAPSHOT</ version >
   < name >angular-demo Maven Webapp</ name >
   < url >http://maven.apache.org</ url >
   < properties >
     < project.build.sourceEncoding >UTF-8</ project.build.sourceEncoding >
     < spring.version >4.2.5.RELEASE</ spring.version >
   </ properties >
     < dependencies >
       < dependency >
         < groupId >junit</ groupId >
         < artifactId >junit</ artifactId >
         < version >4.12</ version >
         < scope >test</ scope >
       </ dependency >
       <!-- spring配置-->
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-aop</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-aspects</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-beans</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-context</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-context-support</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-core</ artifactId >
         < version >${spring.version}</ version >
         < exclusions >
           < exclusion >
             < groupId >commons-logging</ groupId >
             < artifactId >commons-logging</ artifactId >
           </ exclusion >
         </ exclusions >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-expression</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-jdbc</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-jms</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-orm</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-oxm</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-tx</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-web</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-webmvc</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
       < dependency >
         < groupId >org.springframework</ groupId >
         < artifactId >spring-test</ artifactId >
         < version >${spring.version}</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
 
       < dependency >
         < groupId >javax.servlet</ groupId >
         < artifactId >jstl</ artifactId >
         < version >1.2</ version >
         < type >jar</ type >
         < scope >compile</ scope >
       </ dependency >
 
       < dependency >
         < groupId >commons-logging</ groupId >
         < artifactId >commons-logging</ artifactId >
         < version >1.1.1</ version >
       </ dependency >
 
       < dependency >
         < groupId >commons-collections</ groupId >
         < artifactId >commons-collections</ artifactId >
         < version >3.2.1</ version >
       </ dependency >
 
       < dependency >
         < groupId >commons-dbcp</ groupId >
         < artifactId >commons-dbcp</ artifactId >
         < version >1.4</ version >
       </ dependency >
 
       < dependency >
         < groupId >commons-pool</ groupId >
         < artifactId >commons-pool</ artifactId >
         < version >1.5.4</ version >
       </ dependency >
       <!-- mybatis包-->
       < dependency >
         < groupId >org.mybatis</ groupId >
         < artifactId >mybatis</ artifactId >
         < version >3.3.1</ version >
       </ dependency >
       <!--mybatis spring插件-->
       < dependency >
         < groupId >org.mybatis</ groupId >
         < artifactId >mybatis-spring</ artifactId >
         < version >1.2.4</ version >
       </ dependency >
       <!-- mysql连接驱动包-->
       < dependency >
         < groupId >mysql</ groupId >
         < artifactId >mysql-connector-java</ artifactId >
         < version >5.1.26</ version >
       </ dependency >
       <!-- 连接池-->
       < dependency >
         < groupId >c3p0</ groupId >
         < artifactId >c3p0</ artifactId >
         < version >0.9.1.2</ version >
       </ dependency >
       <!-- log4j-->
       < dependency >
         < groupId >log4j</ groupId >
         < artifactId >log4j</ artifactId >
         < version >1.2.14</ version >
       </ dependency >
       <!-- servlet-->
       < dependency >
         < groupId >javax.servlet</ groupId >
         < artifactId >servlet-api</ artifactId >
         < version >2.5</ version >
       </ dependency >
       < dependency >
         < groupId >javax.servlet</ groupId >
         < artifactId >jstl</ artifactId >
         < version >1.2</ version >
       </ dependency >
       <!-- freemarker模板引擎-->
       < dependency >
         < groupId >org.freemarker</ groupId >
         < artifactId >freemarker</ artifactId >
         < version >2.3.23</ version >
       </ dependency >
       <!-- 文件上传 -->
       < dependency >
         < groupId >commons-io</ groupId >
         < artifactId >commons-io</ artifactId >
         < version >2.4</ version >
       </ dependency >
 
       < dependency >
         < groupId >commons-fileupload</ groupId >
         < artifactId >commons-fileupload</ artifactId >
         < version >1.3</ version >
       </ dependency >
 
       <!-- 解析json-->
       < dependency >
         < groupId >com.google.code.gson</ groupId >
         < artifactId >gson</ artifactId >
         < version >2.2.2</ version >
       </ dependency >
 
       <!-- urlrewrite伪静态-->
       < dependency >
         < groupId >org.tuckey</ groupId >
         < artifactId >urlrewritefilter</ artifactId >
         < version >4.0.3</ version >
       </ dependency >
     </ dependencies >
   < build >
     < finalName >angular-demo</ finalName >
     < plugins >
       < plugin >
         < groupId >org.eclipse.jetty</ groupId >
         < artifactId >jetty-maven-plugin</ artifactId >
         < version >9.3.7.v20160115</ version >
         < configuration >
           <!-- 扫描秒数,若非0则为热部署-->
           < scanIntervalSeconds >10</ scanIntervalSeconds >
           < reload >automatic</ reload >
           < stopPort >9966</ stopPort >
           < stopKey >foo</ stopKey >
           < stopWait >10</ stopWait >
           < webApp >
             <!-- 项目根目录-->
             < contextPath >/</ contextPath >
           </ webApp >
           < httpConnector >
             <!-- 服务器端口号-->
             < port >9080</ port >
             < idleTimeout >60000</ idleTimeout >
           </ httpConnector >
           <!-- 请求log-->
           < requestLog  implementation="org.eclipse.jetty.server.NCSARequestLog">
             <!-- log输出目录-->
             < filename >target/yyyy_mm_dd.request.log</ filename >
             <!--<filenameDateformat>yyyy_MM_dd</filenameDateformat>-->
             <!-- log保存天数-->
             < retainDays >90</ retainDays >
             <!-- log是否附加在文件后-->
             < append >true</ append >
             < extended >false</ extended >
             <!-- 时区-->
             < logTimeZone >GMT+8:00</ logTimeZone >
           </ requestLog >
         </ configuration >
       </ plugin >
     </ plugins >
   </ build >
</ project >

  2、配置web.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
< web-app  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_3_0.xsd"
          version="3.0">
   < display-name >Archetype Created Web Application</ display-name >
     < description >springMVC</ description >
 
     <!-- 加载Spring配置文件 -->
     < context-param >
         < param-name >contextConfigLocation</ param-name >
         < param-value >classpath:/config/applicationContext.xml</ param-value >
     </ context-param >
     <!-- 编码过滤器 -->
     < filter >
         < filter-name >encodingFilter</ filter-name >
         < filter-class >org.springframework.web.filter.CharacterEncodingFilter</ filter-class >
         < async-supported >true</ async-supported >
         < 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 >
 
     <!-- urlrewrite-->
     < filter >
         < filter-name >UrlRewriteFilter</ filter-name >
         < filter-class >org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</ filter-class >
     </ filter >
     < filter-mapping >
         < filter-name >UrlRewriteFilter</ filter-name >
         < url-pattern >/*</ url-pattern >
         < dispatcher >REQUEST</ dispatcher >
         < dispatcher >FORWARD</ dispatcher >
     </ filter-mapping >
 
     <!-- 日志记录 -->
     < context-param >
         <!-- 日志配置文件路径 -->
         < param-name >log4jConfigLocation</ param-name >
         < param-value >classpath:config/log4j.properties</ param-value >
     </ context-param >
     < context-param >
         <!-- 日志页面的刷新间隔 -->
         < param-name >log4jRefreshInterval</ param-name >
         < param-value >6000</ param-value >
     </ context-param >
     < listener >
         < listener-class >org.springframework.web.util.Log4jConfigListener</ listener-class >
     </ listener >
 
     <!-- Spring监听 -->
     < listener >
         < listener-class >org.springframework.web.context.ContextLoaderListener</ listener-class >
     </ listener >
 
     <!-- Spring MVC配置 -->
     < servlet >
         < servlet-name >springMVC</ servlet-name >
         < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class >
         <!-- 自定义spring mvc的配置文件名称和路径 -->
         < init-param >
             < param-name >contextConfigLocation</ param-name >
             < param-value >classpath:config/spring-mvc.xml</ param-value >
         </ init-param >
         < load-on-startup >1</ load-on-startup >
     </ servlet >
 
     <!-- spring mvc 请求后缀 -->
     < servlet-mapping >
         < servlet-name >springMVC</ servlet-name >
         < url-pattern >/</ url-pattern >
     </ servlet-mapping >
 
     < error-page >
         < error-code >404</ error-code >
         < location >/error/404</ location >
     </ error-page >
 
     < error-page >
         < error-code >500</ error-code >
         < location >/error/500</ location >
     </ error-page >
 
     < welcome-file-list >
         < welcome-file >/index.jsp</ welcome-file >
         < welcome-file >/index.htm</ welcome-file >
         < welcome-file >/index.html</ welcome-file >
     </ welcome-file-list >
</ web-app >

  3、在resources/config目录下新建applicationContext.xml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<? 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:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
 
     <!-- 自动扫描 -->
     < context:component-scan  base-package="com.liuwenjian.service" />
     < context:component-scan  base-package="com.liuwenjian.dao" />
 
     <!-- 引入文件属性 -->
     <!--<context:property-placeholder location="classpath:config/jdbc.properties" />-->
     < bean  id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         < property  name="location" value="classpath:config/jdbc.properties"/>
     </ bean >
 
     <!-- sqlServer数据源-->
     < bean  id="sqlServerDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
         < property  name="driverClassName" value="${jdbc.sqlserver.driver}"/>
         < property  name="url" value="${jdbc.sqlserver.url}"/>
         < property  name="username" value="${jdbc.sqlserver.username}"/>
         < property  name="password" value="${jdbc.sqlserver.password}"/>
         < property  name="initialSize" value="${jdbc.initialSize}"/>
         < property  name="minIdle" value="${jdbc.minIdle}"/>
         < property  name="maxIdle" value="${jdbc.maxIdle}"/>
         < property  name="maxActive" value="${jdbc.maxActive}"/>
         < property  name="maxWait" value="${jdbc.maxWait}"/>
         < property  name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"/>
         < property  name="removeAbandoned" value="${jdbc.removeAbandoned}"/>
         < property  name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
         < property  name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
         < property  name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
         < property  name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}"/>
         < property  name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
     </ bean >
 
     <!-- mysql数据源-->
     < bean  id="mySqlDataSource" class="org.apache.commons.dbcp.BasicDataSource"
           destroy-method="close">
         < property  name="driverClassName" value="${jdbc.mysql.driver}"/>
         < property  name="url" value="${jdbc.mysql.url}"/>
         < property  name="username" value="${jdbc.mysql.username}"/>
         < property  name="password" value="${jdbc.mysql.password}"/>
         < property  name="initialSize" value="${jdbc.initialSize}"/>
         < property  name="minIdle" value="${jdbc.minIdle}"/>
         < property  name="maxIdle" value="${jdbc.maxIdle}"/>
         < property  name="maxActive" value="${jdbc.maxActive}"/>
         < property  name="maxWait" value="${jdbc.maxWait}"/>
         < property  name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"/>
         < property  name="removeAbandoned" value="${jdbc.removeAbandoned}"/>
         < property  name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
         < property  name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
         < property  name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
         < property  name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}"/>
         < property  name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
     </ bean >
 
     <!-- 数据源选择,targetDataSources中选择数据源,若找不到,则使用defaultTargetDataSource-->
     < bean  id="multipleDataSource" class="com.liuwenjian.common.MultipleDataSource">
         < property  name="defaultTargetDataSource" ref="mySqlDataSource"/>
         < property  name="targetDataSources">
             < map >
                 < entry  key="mySqlDataSource" value-ref="mySqlDataSource"/>
                 < entry  key="sqlServerDataSource" value-ref="sqlServerDataSource"/>
             </ map >
         </ property >
     </ bean >
 
     <!-- 配置mybatis的sqlSessionFactory -->
     < bean  id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
         < property  name="dataSource" ref="multipleDataSource" />
         <!-- 自动扫描mappers.xml文件 ,要加上classpath:com/...-->
         <!--<property name="mapperLocations" value="classpath:com/liuwenjian/mappers/*.xml"></property>-->
         <!-- mybatis配置文件 -->
         < property  name="configLocation" value="classpath:config/mybatis-config.xml"></ property >
     </ bean >
 
     <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
     < bean  class="org.mybatis.spring.mapper.MapperScannerConfigurer">
         < property  name="basePackage" value="com.liuwenjian.dao" />
         < property  name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></ property >
     </ bean >
 
     <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
     < bean  id="transactionManager"
           class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
         < property  name="dataSource" ref="mySqlDataSource" />
     </ bean >
 
     <!-- 配置事务通知属性 -->
     < tx:advice  id="txAdvice" transaction-manager="transactionManager">
         <!-- 定义事务传播属性 -->
         < tx:attributes >
             < tx:method  name="insert*" propagation="REQUIRED" />
             < tx:method  name="update*" propagation="REQUIRED" />
             < tx:method  name="edit*" propagation="REQUIRED" />
             < tx:method  name="save*" propagation="REQUIRED" />
             < tx:method  name="add*" propagation="REQUIRED" />
             < tx:method  name="new*" propagation="REQUIRED" />
             < tx:method  name="set*" propagation="REQUIRED" />
             < tx:method  name="remove*" propagation="REQUIRED" />
             < tx:method  name="delete*" propagation="REQUIRED" />
             < tx:method  name="change*" propagation="REQUIRED" />
             < tx:method  name="get*" propagation="REQUIRED" read-only="true" />
             < tx:method  name="find*" propagation="REQUIRED" read-only="true" />
             < tx:method  name="load*" propagation="REQUIRED" read-only="true" />
             < tx:method  name="*" propagation="REQUIRED" read-only="true" />
         </ tx:attributes >
     </ tx:advice >
 
     <!-- 配置事务切面 -->
     < aop:config >
         < aop:pointcut  id="serviceOperation"
         expression="execution(* com.liuwenjian.service.*.*(..))" />
         < aop:advisor  advice-ref="txAdvice" pointcut-ref="serviceOperation" />
     </ aop:config >
</ beans >

  在文件中引入的jdbc.properties文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#============================================================================
# MySQL
#============================================================================
jdbc.mysql.driver=com.mysql.jdbc.Driver
jdbc.mysql.url=jdbc:mysql://localhost:9081/angular-demo?useUnicode=true&characterEncoding=utf8
jdbc.mysql.username=root
jdbc.mysql.password=root
 
#============================================================================
# MS SQL Server
#============================================================================
jdbc.sqlserver.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.sqlserver.url=jdbc:sqlserver://127.0.0.1:1433;database=angular-demo;
jdbc.sqlserver.username=root
jdbc.sqlserver.password=root
 
#============================================================================
# ORACLE
#============================================================================
jdbc.orcl.driver=oracle.jdbc.OracleDriver
jdbc.orcl.url=jdbc:oracle:thin:@localhost:1526:angular-demo
jdbc.orcl.username=root
jdbc.orcl.password=root
 
#============================================================================
# common settings
#============================================================================
jdbc.initialSize=5
jdbc.minIdle=5
jdbc.maxIdle=20
jdbc.maxActive=100
jdbc.maxWait=100000
jdbc.defaultAutoCommit=false
jdbc.removeAbandoned=true
jdbc.removeAbandonedTimeout=600
jdbc.testWhileIdle=true
jdbc.timeBetweenEvictionRunsMillis=60000
jdbc.numTestsPerEvictionRun=20
jdbc.minEvictableIdleTimeMillis=300000

  mybatis-config.xml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<? xml  version="1.0" encoding="UTF-8"?>
<! DOCTYPE  configuration PUBLIC
         "-//mybatis.org//DTD Config 3.0//EN"
         "http://mybatis.org/dtd/mybatis-3-config.dtd">
< configuration >
     < settings >
         <!-- setting name="cacheEnable" value="true"/-->
         < setting  name="useGeneratedKeys" value="false"/>
         < setting  name="logImpl" value="LOG4J"/> <!--增加mybatis日志-->
     </ settings >
     < mappers >
         <!--<mapper resource="com/liuwenjian/mappers/userMapper.xml" />-->
     </ mappers >
</ configuration >

  spring-mvc.xml配置

前端模板解析最常用的是内置jsp,velocity和freemarker,这边选择的是freemarker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<? 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:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
 
     <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
     < mvc:annotation-driven  />
 
     <!-- 使用注解的包,包括子集 -->
     < context:component-scan  base-package="com.liuwenjian.controller" />
 
     <!-- 解决js,css,images访问不到的问题-->
     < mvc:resources  mapping="/js/**" location="/js/" />
     < mvc:resources  mapping="/css/**" location="/css/" />
     < mvc:resources  mapping="/images/**" location="/images/" />
     < mvc:resources  mapping="/template/**" location="/template/" />
 
     <!-- 文件上传配置注意:这里申明的id必须为multipartResolver -->
     < bean  id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
         < property  name="maxUploadSize" value="500000"/>
     </ bean >
 
     <!-- 简单的异常处理 -->
     < bean  id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
         < property  name="exceptionMappings">
             < props >
                 <!-- 映射目录为/WEB-INF/jsp/error/upload_error.jsp -->
                 < prop  key="org.springframework.web.multipart.MaxUploadSizeExceededException">/error/upload_error</ prop >
             </ props >
         </ property >
     </ bean >
 
     <!-- freemarker配置资源文件引入-->
     < bean  id="freemarkerConfiguration"
           class="org.springframework.beans.factory.config.PropertiesFactoryBean">
         < property  name="location" value="classpath:config/freemarker.properties" />
     </ bean >
 
     <!-- 配置freeMarker的模板路径 -->
     < bean  id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
         < property  name="templateLoaderPath">
             < value >/WEB-INF/views/</ value >
         </ property >
         < property  name="freemarkerVariables">
             < map >
                 < entry  key="xml_escape" value-ref="fmXmlEscape"/>
             </ map >
         </ property >
         < property  name="freemarkerSettings" ref="freemarkerConfiguration"></ property >
     </ bean >
 
     < bean  id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
 
     <!-- 针对freemarker的视图解析器配置 -->
     < bean  id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
         < property  name="cache" value="true" />
         < property  name="prefix" value="" />
         < property  name="suffix" value=".ftl" />
         < property  name="viewClass">
             < value >org.springframework.web.servlet.view.freemarker.FreeMarkerView
             </ value >
         </ property >
         < property  name="contentType" value="text/html;charset=UTF-8"></ property >
         <!-- 在ftl页面中使用request.contextPath就可以获得contextPath-->
         < property  name="requestContextAttribute" value="request" />
         <!-- 使用这些宏,必须设置FreeMarkerViewResolver的exposeMacroHelpers属性为true -->
         < property  name="exposeSpringMacroHelpers" value="true" />
         <!-- 将请求和会话属性作为变量暴露给freemaker模板使用-->
         < property  name="exposeRequestAttributes" value="true" />
         < property  name="exposeSessionAttributes" value="true" />
     </ bean >
</ beans

  freemarker.properties配置

1
2
3
4
5
6
7
8
9
10
11
tag_syntax=auto_detect
template_update_delay=60//模板更新时间
default_encoding=UTF-8//默认编码
output_encoding=UTF-8//输出编码
locale=zh_CN//使用语言
date_format=yyyy-MM-dd
time_format=HH:mm:ss
datetime_format=yyyy-MM-dd HH:mm:ss
number_format=0.##########
classic_compatible=true
template_exception_handler=ignore//模板类型处理

  log4j.properties配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
##define output style
ConversionPattern=%d %-5p [%t] %c - %m%n
 
log4j.rootLogger=DEBUG,Console
log4j.logger.com.cnblogs.lzrabbit=DEBUG
log4j.logger.org.springframework=ERROR
log4j.logger.org.mybatis=ERROR
log4j.logger.org.apache.ibatis=ERROR
log4j.logger.org.quartz=ERROR
log4j.logger.org.apache.axis2=ERROR
log4j.logger.org.apache.axiom=ERROR
log4j.logger.org.apache=ERROR
log4j.logger.httpclient=ERROR
#log4j.additivity.org.springframework=false
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Threshold=DEBUG 
log4j.appender.Console.Target=System.out 
log4j.appender.Console.layout=org.apache.log4j.PatternLayout 
log4j.appender.Console.layout.ConversionPattern=${ConversionPattern}
#log4j.appender.Console.encoding=UTF-8
 
#org.apache.log4j.DailyRollingFileAppender
log4j.appender.DailyFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DailyFile.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.DailyFile.File=${myApp.root}/logs/daily.log
log4j.appender.DailyFile.Append=true
log4j.appender.DailyFile.Threshold=DEBUG
log4j.appender.DailyFile.layout=org.apache.log4j.PatternLayout
log4j.appender.DailyFile.layout.ConversionPattern=${ConversionPattern}
log4j.appender.DailyFile.encoding=UTF-8
 
#    %c 输出日志信息所属的类的全名
#    %d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyy-MM-dd HH:mm:ss},
#      输出类似:2016-03-10 22:10:11
#    %f 输出日志信息所属的类的类名
#    %l 输出日志事件的发生位置,即输出日志信息的的语句处于它所在的类的第几行
#    %m 输出代码中指定的信息,如log(message)中的message
#    %n 输出一个回车换行符,Windows平台为"rn",Unix平台为"n"
#    %p 输出优先级,即DEBUG.INFO,WARN,ERROR,FATAL.如果是调用debug()输出的,则为DEBUG,以此类推
#    %r 输出自应用启动到输出该日志信息所耗费的毫秒数
#    %t 输出产生该日志的线程名

在pom文件内部,已添加内嵌jetty服务器,可以直接使用。

配置完成,就可以使用内嵌的服务器启动了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值