ssm配置文件

 jdbc.properties 

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/bsssm?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
jdbc.username=root
jdbc.password=1234

applicationContext_dao.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 https://www.springframework.org/schema/context/spring-context.xsd">
   <!--读取jdbc.properties-->
   <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
   <!--声明数据源DataSource,作用是连接数据库-->
   <bean id="myDataSource" class="com.alibaba.druid.pool.DruidDataSource"
         init-method="init" destroy-method="close">
       <!--set注入DruidDataSource提供连接数据库信息-->
       <property name="driverClassName" value="${jdbc.driver}"></property>
       <property name="url" value="${jdbc.url}"></property>
       <property name="username" value="${jdbc.username}"></property>
       <property name="password" value="${jdbc.password}"></property>

   </bean>
   <!--配置SqlSessionFactoryBean-->
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
       <!--创建数据源-->
       <property name="dataSource" ref="myDataSource"></property>
       <!--配置mybatis的核心配置文件-->
       <property name="configLocation" value="classpath:SqlMapConfig.xml"></property>
       <!--配置实体类-->
       <property name="typeAliasesPackage" value="com.bjpowernode.pojo"></property>
   </bean>

   <!--创建dao对象,使用SqlSession的getMapper(StudentDao.class)-->
   <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory">

       </property>
       <property name="basePackage" value="com.bjpowernode.mapper"></property>
   </bean>
</beans>

applicationContext_service.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 https://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 https://www.springframework.org/schema/aop/spring-aop.xsd">
<!--设置业务逻辑层包的扫描器.使用service的注解-->
<context:component-scan base-package="com.bjpowernode.service"></context:component-scan>

   <!--事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="myDataSource"></property>
</bean>
   <!--添加事务的切面-->
<tx:advice id="myadivce" transaction-manager="transactionManager">
   <tx:attributes>
       <tx:method name="*select*" read-only="true"/>
       <tx:method name="*find*" read-only="true"/>
       <tx:method name="*get*" read-only="true"/>
       <tx:method name="*search*" read-only="true"/>
       <tx:method name="*insert*" propagation="REQUIRED"/>
       <tx:method name="*save*" propagation="REQUIRED"/>
       <tx:method name="*add*" propagation="REQUIRED"/>
       <tx:method name="*delete*" propagation="REQUIRED"/>
       <tx:method name="*remove*" propagation="REQUIRED"/>
       <tx:method name="*clear*" propagation="REQUIRED"/>
       <tx:method name="*update*" propagation="REQUIRED"/>
       <tx:method name="*modify*" propagation="REQUIRED"/>
       <tx:method name="*change*" propagation="REQUIRED"/>
       <tx:method name="*set*" propagation="REQUIRED"/>
       <tx:method name="*" propagation="SUPPORTS"/>
   </tx:attributes>
</tx:advice>

   <!--完成切面和切入点的植入-->
   <aop:config>
       <aop:pointcut id="mypointcut" expression="execution(* com.bjpowernode.service.*.*(..))"/>
       <aop:advisor advice-ref="myadivce" pointcut-ref="mypointcut"></aop:advisor>
   </aop:config>
</beans>

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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--设置包扫描器-->
   <context:component-scan base-package="com.bjpowernode.controller"></context:component-scan>

   <!--视图解析器-->
   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix" value="/admin/"></property>
       <property name="suffix" value=".jsp"></property>
   </bean>

   <!--文件上传核心组件-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>


   <!--注解驱动-->
   <mvc:annotation-driven></mvc:annotation-driven>
</beans>

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>

   <settings>

       <setting name="logImpl" value="STDOUT_LOGGING"/>

   </settings>
<!--分页插件的配置-->
<plugins>
   <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
</configuration>

web.xml 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
        version="4.0">
<!--字符编码过滤器-->
<filter>
   <filter-name>encode</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>
   <init-param>
       <param-name>forceRequestEncoding</param-name>
       <param-value>true</param-value>
   </init-param>
   <init-param>
       <param-name>forceResponseEncoding</param-name>
       <param-value>true</param-value>
   </init-param>
</filter>
   <filter-mapping>
       <filter-name>encode</filter-name>
       <url-pattern>/*</url-pattern>
   </filter-mapping>
   <!--中央调度器-->
   <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.xml</param-value>
           </init-param>
       <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
       <servlet-name>springmvc</servlet-name>
       <url-pattern>*.action</url-pattern>
   </servlet-mapping>
   <!--注册spring框架-->
   <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
   <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:applicationContext_*.xml</param-value>
   </context-param>
</web-app>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值