SSM框架配置整合

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:mvc="http://www.springframework.org/schema/mvc"
	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.3.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

	<!-- 开启注解 -->
	<context:component-scan base-package="com.zhcx" />

	<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<!-- 配置资源文件 -->
		<property name="locations">
			<list>
				<value>classpath:db.properties</value>
			</list>
		</property>
	</bean>

	<!--配置数据源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driver}" />
		<property name="jdbcUrl" value="${jdbc.url}" />
		<property name="user" value="${jdbc.user}" />
		<property name="password" value="${jdbc.password}" />
	</bean>

	<!-- 配置sqlSessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<!-- 指定mapper文件的位置 -->
		<property name="mapperLocations" value="classpath:com/zhcx/mapper/*.xml"></property>
		<!--指定MyBatis的核心配置文件 -->
		<property name="configLocation" value="classpath:mybatis-config.xml" />
	</bean>

	<!-- 接口开发,扫描mapper包 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.zhcx.mapper"></property>
	</bean>
<!-- 	文件上传对象注入 -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>

	<!-- TODO -->
	<bean id="busServiceImpl" class="com.zhcx.service.impl.BusServiceImpl"></bean>

<!-- 	配置事务之具体的平台事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
<!-- 	<tx:annotation-driven transaction-manager="transactionManager" /> -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="delBusByIdAllTra" />
			<tx:method name="insBusAllTra" />
		</tx:attributes>
	</tx:advice>
	
	<aop:config>
<!--  		<aop:pointcut expression="execution(* com.zhcx.service.impl.BusServiceImpl.*(..))" id="txPointcut"/>  -->
		<aop:pointcut expression="bean(*Impl)" id="txPointcut" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />
	</aop:config>
</beans>

db.properties配置信息

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///zhcx
jdbc.user=root
jdbc.password=root
log4j.properties配置信息
    log4j.rootLogger=DEBUG,A1
log4j.logger.com.taotao = DEBUG
log4j.logger.org.mybatis = DEBUG

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%5p - %m%n

mybatis-config.xml配置信息

<?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="mapUnderscoreToCamelCase" value="true" />
	</settings>
	<!-- 别名定义 -->
	<typeAliases>
		<package name="com.zhcx.pojo" />
	</typeAliases>
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageHelper">
			<property name="dialect" value="mysql"/>
			<property name="rowBoundsWithCount" value="true"/>
		</plugin>
	</plugins>
</configuration>
springmvc-config.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:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.3.xsd">

	<!-- 配置扫描器 -->
	<context:component-scan base-package="com.zhcx"></context:component-scan>

	<!-- 注解驱动:配置处理器映射器和适配器 -->
	<mvc:annotation-driven></mvc:annotation-driven>

	<!-- 处理静态资源 -->
	<mvc:default-servlet-handler />
	<!--配置静态资源的访问映射,此配置中的文件,将不被前端控制器拦截 -->
	<mvc:resources mapping="/js/**" location="/WEB-INF/js/" />
	<mvc:resources mapping="/css/**" location="/WEB-INF/css/" />
	<mvc:resources mapping="/imgs/**" location="/WEB-INF/imgs/" />
	<mvc:resources mapping="/ueditor1.4.3.3/**" location="/WEB-INF/ueditor1.4.3.3/" />

	<!-- 配置视图解析器 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>

	<!--配置拦截器 -->
	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/**" />
			<mvc:exclude-mapping path="/**/*.css" />
			<mvc:exclude-mapping path="/**/*.js" />
			<mvc:exclude-mapping path="/**/*.png" />
			<mvc:exclude-mapping path="/**/*.gif" />
			<mvc:exclude-mapping path="/**/*.jpg" />
			<mvc:exclude-mapping path="/**/*.jpeg" />
			<mvc:exclude-mapping path="/**/*login*" />
			<mvc:exclude-mapping path="/views/login.jsp" />
			<mvc:exclude-mapping path="/**/validate*" />
			<bean class="com.zhcx.interceptor.MyInterceptor"></bean>
		</mvc:interceptor>
	</mvc:interceptors>

	<!-- 定义文件上传解析器 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 设定默认编码 -->
		<property name="defaultEncoding" value="UTF-8"></property>
		<!-- 设定文件上传的最大值5MB,5*1024*1024 ,指的是所有文件的总和 -->
		<property name="maxUploadSize" value="5242880"></property>
	</bean>

	<!-- excel 视图 -->
	<bean id="export-bus" class="com.zhcx.ExcelView.BusExcelView"></bean>
	<bean id="export-route" class="com.zhcx.ExcelView.RouteExcelView"></bean>
	<bean id="export-team" class="com.zhcx.ExcelView.TeamExcelView"></bean>
	<!-- 对上面定义视图解析器(通过bean对象查找视图) -->
	<bean
		class="org.springframework.web.servlet.view.BeanNameViewResolver">
		<property name="order" value="1"></property>
	</bean>
</beans>

web.xml配置信息

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	version="2.5">
	<display-name>traffics</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
	<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>
	
	<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:springmvc-config.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>springmvc</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	<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>

	
</web-app>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值