SSM环境搭建
Posted huanggy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSM环境搭建相关的知识,希望对你有一定的参考价值。
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环境搭建的主要内容,如果未能解决你的问题,请参考以下文章