dao层配置文件
application.xml文件
路径:resources->spring->application.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" xsi:schemaLocation="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.xsd"> <!-- 导入外部资源--> <context:property-placeholder location="classpath:spring/jdbc.properties"></context:property-placeholder> <!-- 创建spring-jdbc的数据源--> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.sql.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.userpwd}"/> </bean> <!-- 创建SqlSessionFactory对象--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!--mybatis 其它配置(分页助手的配置)--> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <props> <!-- 分页的相关配置参数 用哪个数据库--> <prop key="helperDialect">mysql</prop> </props> </property> </bean> </array> </property> <!--第二种分页配置文件方式--> <!--<property name="configLocation" value="classpath:sqlMapConfig.xml"></property>--> </bean> <!-- 扫描包 接口动态代理对象--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="cn.kgc.dao"/> </bean> </beans>
jdbc.properpies文件
路径: resources->spring->jdbc.properpies
jdbc.driver:com.mysql.jdbc.Driver jdbc.sql.url:jdbc:mysql://localhost:3306/travel jdbc.username:root jdbc.userpwd:admin
log4j2.xml文件
路径:resources->log4j2.xml
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="warn" monitorInterval="30" strict="true" schema="Log4J-V2.2.xsd"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <!-- 将日志输出到控制台 --> <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %level [%C{36}.%M] - %msg%n"/> </Console> <!--将日志输出到文件中--> <file name="myLogFile" fileName="d:/log/ssm.log" append="true"> <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %level [%C{36}.%M] - %msg%n"/> </file> </Appenders> <Loggers> <!-- 全局配置 --> <root level="info"> <!--普通日志要在哪里显示--> <appenderRef ref="Console"/> <appender-ref ref="myLogFile"/> </root> <!-- 业务层日志 --> <logger name="com.itheima.service" level="debug" additivity="false"> <appender-ref ref="Console"/> <appender-ref ref="myLogFile"/> </logger> <!-- 持久层日志 --> <logger name="com.itheima.dao" level="debug" additivity="false"> <appender-ref ref="Console"/> <appender-ref ref="myLogFile"/> </logger> <!-- 事务日志 --> <logger name="org.springframework.jdbc" level="debug" additivity="false"> <appender-ref ref="Console"/> <appender-ref ref="myLogFile"/> </logger> </Loggers> </Configuration>
sqlMapConfig.xml文件
分页助手文件
路径:resources->sqlMapConfig.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>
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
</plugins>
</configuration>
service层配置文件
路径:resources->spring->spring.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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="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.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"> <!-- 引入持久层的配置文件--> <!-- <import resource="classpath*:applicationContext.xml"></import>--> <!-- 扫描包--> <context:component-scan base-package="cn.kgc.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="find*" read-only="true" propagation="SUPPORTS"/> <tx:method name="query*" read-only="true" propagation="SUPPORTS"/> <tx:method name="get*" read-only="true" propagation="SUPPORTS"/> <tx:method name="*" read-only="false" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <!-- aop切面配置--> <aop:config> <aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.kgc.service.impl.*.*(..))"></aop:advisor> </aop:config> </beans>
controller层配置文件
springMVC.xml文件
路径:resources->springMVC.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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 扫描包--> <context:component-scan base-package="cn.kgc.controller"></context:component-scan> <!-- 视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/pages/"></property> <property name="suffix" value=".jsp"></property> </bean> <!-- 注解驱动--> <mvc:annotation-driven></mvc:annotation-driven> <!-- 静态资源放行--> <mvc:default-servlet-handler></mvc:default-servlet-handler> </beans>
spring-security.xml文件
路径:resources->spring-security.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:security="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> <!-- 不拦截静态资源--> <security:http pattern="/css/**" security="none"/> <security:http pattern="/img/**" security="none"/> <security:http pattern="/plugins/**" security="none"/> <!-- 不拦截login,不拦截error,不拦截谷歌自带图标插件--> <security:http pattern="/login.jsp" security="none"/> <security:http pattern="/errror.jsp" security="none"/> <security:http pattern="/favicon.ico" security="none"/> <!-- 规定拦截规则,auto-config="使用自带页面",use-expressions 是否使用spel 表达式--> <security:http auto-config="true" use-expressions="false"> <security:intercept-url pattern="/**" access="ROLE_USER"/> <!--使用安全框架 使用的页面 login-page 指的是登录页面 login-processing-url 登录请求路径 -登录必须使用该路径 default-target-url 登录成功后 进入的页面 authentication-failure-url 登录失败后 进入的页面 --> <security:form-login login-page="/login.jsp" login-processing-url="/login" default-target-url="/index.jsp" authentication-failure-url="/login.jsp" /> <!--关闭跨域请求--> <security:csrf disabled="true"/> <!--退出--> <security:logout invalidate-session="true" logout-url="/logout" logout-success-url="/login.jsp"/> </security:http> <!-- 配置认证登录信息 认证管理器自带账户密码--> <security:authentication-manager> <security:authentication-provider user-service-ref="userService"> <!-- spring-security自带的加密方式--> <security:password-encoder ref="passwordEncoder"/> <!-- <security:user-service>--> <!--临时账户密码 authorities:指定用户的认证角色 {noop}不加密--> <!-- <security:user name="admin" password="{noop}admin" authorities="ROLE_USER"></security:user>--> <!-- </security:user-service>--> </security:authentication-provider> </security:authentication-manager> <!-- 把spring-security加密所需包,放进spring容器--> <bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/> </beans>
原文:https://www.cnblogs.com/liugaoyanging/p/11495385.html