天天看點

整合ssm所需的配置檔案

整合ssm所需配置檔案

Mybatis配置檔案

<?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.fr.bean"/>
	</typeAliases>
  </configuration>
           

spring配置檔案

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.springframework.org/schema/beans"
	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.2.xsd
				http://www.springframework.org/schema/context
				http://www.springframework.org/schema/context/spring-context-4.2.xsd
				http://www.springframework.org/schema/aop
				http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
				http://www.springframework.org/schema/tx
				http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
				http://www.springframework.org/schema/util
				http://www.springframework.org/schema/util/spring-util-4.1.xsd">
	<context:annotation-config></context:annotation-config>
	<context:component-scan base-package="com.fr">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="jdbcUrl" value="jdbc:mysql:///userinfo"></property>
		<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
		<property name="user" value="root"></property>
		<property name="password" value="12345678"></property>
	</bean>
	<bean class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<property name="configLocation" value="classpath:MyBatis-config.xml"></property>
		<property name="mapperLocations" value="classpath:dao/*.xml"></property>
	</bean>
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.fr.dao"></property>
	</bean>
	<context:component-scan base-package="com.fr.service" />
	<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="save*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
			<tx:method name="get*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
			<tx:method name="add*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<aop:pointcut expression="execution(* com.fr.service.*.*(..))" id="txPc"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="txPc"/>
	</aop:config>
</beans>
           

springmvc配置檔案

<?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.1.xsd
                       http://www.springframework.org/schema/mvc 
                       http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
                       http://www.springframework.org/schema/context 
                       http://www.springframework.org/schema/context/spring-context-4.1.xsd">
    
    <!-- 掃描控制器的包 -->
    <context:component-scan base-package="com.fr.controller">
    </context:component-scan>
    
    <!-- ? -->
    <mvc:default-servlet-handler/>
    
    <!-- 開啟注解 -->
    <mvc:annotation-driven></mvc:annotation-driven>
    
    <!-- 攔截器 -->
<!--      <mvc:interceptors>
    	<mvc:interceptor>
    		<mvc:mapping path="/**"/>
    		<bean class="com.fr.interceptor.LoginInterceptor"></bean>
    	</mvc:interceptor>
    </mvc:interceptors> -->
    
    <!-- 視圖解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    	<!-- 配置視圖真正的存放位置 prefix為路徑,suffix為字尾 -->
    	<property name="prefix" value="/"></property>
    	<property name="suffix" value=".jsp"></property>
    </bean>
</beans>
           

log4j.properties

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

           

繼續閱讀