SSM環境搭建
阿新 • • 發佈:2018-07-03
設置 www. one ica mybatis chang eval pro basename
spring配置文件 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:p="http://www.springframework.org/schema/p" 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/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- db.properties --> <!-- <context:property-placeholder location="classpath:db.properties" /> --> <!-- 掃描,支持spring註解 --> <context:component-scan base-package="com.grts.serviceImpl,com.grts.actions" /> <!-- dataSourceC3p0 --> <bean id="dataSourceC3p0" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql:///test" /> <property name="user" value="root" /> <property name="password" value="root" /> </bean> <!-- mybatis sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 引用數據源 --> <property name="dataSource" ref="dataSourceC3p0" /> <!-- 加載mybatis配置文件 --> <property name="configLocation" value="classpath:spring-mybatis.xml" /> <!-- mybatis別名 --> <property name="typeAliasesPackage" value="com.grts.pojo" /> </bean> <!-- mybatis mapper --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.grts.mapper" /> </bean> </beans>
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> <!-- 配置延遲加載 --> <settings> <!-- 打開延遲加載 --> <setting name="lazyLoadingEnabled" value="true" /> <!-- 延遲加載的方式:按需加載 --> <setting name="aggressiveLazyLoading" value="false"/> </settings> </configuration>
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:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <!-- 開啟註解 --> <mvc:annotation-driven validator="validator"></mvc:annotation-driven> <!-- 掃描 --> <context:component-scan base-package="com.grts.actions"></context:component-scan> <mvc:annotation-driven/> <!-- 配置攔截器 --> <mvc:interceptors> <mvc:interceptor> <!-- 一個*:攔截當前路徑(action中的方法) /stu/* ->>>> 攔截 stu 下的所有請求 兩個*:攔截所有請求(action的方法) /** ->>>> 攔截所有請求 --> <mvc:mapping path="/**" /> <!-- 放開特定的方法(指定方法不攔截,別的都攔截) --> <mvc:exclude-mapping path="/stu/queryAll" /> <!-- 攔截器class --> <bean class="com.grts.interceptor.TestInterceptor"></bean> </mvc:interceptor> </mvc:interceptors> <!--添加對JSR-303驗證框架的支持 --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="providerClass" value="org.hibernate.validator.HibernateValidator" /> <!--不設置則默認為classpath下的 ValidationMessages.properties --> <property name="validationMessageSource" ref="validatemessageSource" /> </bean> <bean id="validatemessageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="classpath:ValidateMessages" /> <property name="fileEncodings" value="utf-8" /> <property name="cacheSeconds" value="120" /> </bean> </beans>
SSM環境搭建