ssm配置
2022-06-09 约 1140 字
预计阅读 3 分钟
次阅读
Spring配置-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
<?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:tx= "http://www.springframework.org/schema/tx"
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" >
<!--组件扫描 扫描service和mapper-->
<context:component-scan base-package= "com.pd" >
<!--排除controller的扫描-->
<context:exclude-filter type= "annotation" expression= "org.springframework.stereotype.Controller" />
</context:component-scan>
<!--加载propeties文件-->
<context:property-placeholder location= "classpath:jdbc.properties" ></context:property-placeholder>
<!--配置数据源信息-->
<bean id= "dataSource" class= "com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name= "driverClass" value= "${jdbc.driver}" ></property>
<property name= "jdbcUrl" value= "${jdbc.url}" ></property>
<property name= "user" value= "${jdbc.username}" ></property>
<property name= "password" value= "${jdbc.password}" ></property>
</bean>
<!--配置sessionFactory, spring集成mybatis-->
<bean id= "sqlSessionFactory" class= "org.mybatis.spring.SqlSessionFactoryBean" >
<property name= "dataSource" ref= "dataSource" ></property>
<!--加载mybatis核心文件-->
<property name= "configLocation" value= "classpath:mybatis-spring.xml" ></property>
</bean>
<!--扫描mapper所在的包 为mapper创建实现类-->
<bean class= "org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name= "basePackage" value= "com.pd.mapper" ></property>
</bean>
<!--声明式事务控制-->
<!--平台事务管理器-->
<bean id= "transactionManager" class= "org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "dataSource" ref= "dataSource" ></property>
</bean>
<!--配置事务增强-->
<tx:advice id= "txAdvice" transaction-manager= "transactionManager" >
<tx:attributes>
<tx:method name= "*" />
</tx:attributes>
</tx:advice>
<!--事务的aop织入-->
<aop:config>
<!-- <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.pd.service.impl.*.*(..))"></aop:advisor>-->
<aop:advisor advice-ref= "txAdvice" pointcut= "execution(* com.pd.controller.*.*(..))" ></aop:advisor>
</aop:config>
<!--事务的注解驱动-->
<!-- <tx:annotation-driven/>-->
</beans>
SpringMVC.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
<?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.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" >
<!--Controller的组件扫描-->
<context:component-scan base-package= "com.pd.controller" >
<context:include-filter type= "annotation" expression= "org.springframework.stereotype.Controller" />
</context:component-scan>
<!--mvc的注解驱动-->
<mvc:annotation-driven />
<!--开放资源的访问-->
<!--<mvc:resources mapping="/js/**" location="/js/"/>
<mvc:resources mapping="/img/**" location="/img/"/>-->
<mvc:default-servlet-handler/>
<!--配置内部资源视图解析器-->
<bean id= "viewResolver" class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<!-- /jsp/success.jsp -->
<property name= "prefix" value= "/WEB-INF/pages/" ></property>
<property name= "suffix" value= ".jsp" ></property>
</bean>
<!--配置处理器映射器-->
<!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</list>
</property>
</bean>-->
<!-- <!–配置文件上传解析器–>-->
<!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">-->
<!-- <property name="defaultEncoding" value="UYF-8"/>-->
<!-- <property name="maxUploadSize" value="500000"/>-->
<!-- </bean>-->
</beans>
Mybatis-Spring.xml
1
2
3
4
5
6
7
8
9
10
11
12
<?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>
<!--定义别名-->
<typeAliases>
<package name= "com.pd.pojo" ></package>
</typeAliases>
</configuration>
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
<?xml version="1.0" encoding="UTF-8"?>
<web-app version= "3.0" 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" >
<!--配置全局过滤的filter-->
<filter>
<filter-name> CharacterEncodingFilter</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> CharacterEncodingFilter</filter-name>
<url-pattern> /*</url-pattern>
</filter-mapping>
<!--配置SpringMVC的前端控制器-->
<servlet>
<servlet-name> DispatcherServlet</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name> contextConfigLocation</param-name>
<param-value> classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup> 1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name> DispatcherServlet</servlet-name>
<url-pattern> /</url-pattern>
</servlet-mapping>
<!--全局初始化参数-->
<context-param>
<param-name> contextConfigLocation</param-name>
<param-value> classpath:applicationContext.xml</param-value>
</context-param>
<!--配置监听器-->
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
jdbc.properties
1
2
3
4
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm
jdbc.username=root
jdbc.password=1234
log4j.properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
# Hibernate, Relational Persistence for Idiomatic Java
#
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
#
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=all, stdout