zoukankan      html  css  js  c++  java
  • java的SSM配置文件 三部分。 idea系

    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: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">
    <!--扫描dao层的包 创建动态代理对象存入到spring容器中-->
    <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="cn.kgc.dao"/>
    </bean>-->
    <!--<context:component-scan base-package="cn.kgc.dao"/>-->
    <!--<context:component-scan base-package="cn.kgc.service"/>-->
    <!--____________________________________________________________________________________________________-->
    <!--开启注解扫描,并设置不扫描Controller-->
    <context:component-scan base-package="cn.kgc">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!--_____________________________________________________________________________________________________-->
    <!--引入外部资源-->
    <context:property-placeholder location="classpath:config.properties"/>
    <!--数据源-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${driver}"></property>
    <property name="url" value="${url}"></property>
    <property name="username" value="${root}"></property>
    <property name="password" value="${password}"></property>
    </bean>
    <!--创建sqlsessionfactory-->
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!--引入数据源 或者引入mybatis的配置文件-->
    <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--____________________________________________________________________________________________________-->
    <!--3.配置dao层-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" id="mapperScannerConfigurer">
    <property name="basePackage" value="cn.kgc.dao"/>
    </bean>
    <!--____________________________________________________________________________________________________-->
    <!--业务层配置-->
    <!--事务管理对象-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--增强事务管理对象-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <!--该类方法 只读 如果有事物 加入事物执行 -->
    <tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
    <tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
    <tx:method name="query*" 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: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
    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"/>-->
    <!--_____________________________________________________________________________________________________-->
    <!--开启注解扫描,只扫描Controller-->
    <context:component-scan base-package="cn.kgc">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!--_____________________________________________________________________________________________________-->
    <!--注解驱动-->
    <mvc:annotation-driven></mvc:annotation-driven>
    <!-- 静态资源方行-->
    <mvc:default-servlet-handler></mvc:default-servlet-handler>
    <!--<mvc:annotation-driven/>-->
    <!--视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/pages/"/>
    <property name="suffix" value=".jsp"/>
    </bean>
    </beans>
      WEB-INF下的web.xml配置文件
    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd" >
    <!--
    <?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">
    -->

    <web-app>
    <display-name>Archetype Created Web Application</display-name>
    <!--配置一个全局的参数 指定spring 容器配置文件-->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContex.xml</param-value>
    </context-param>

    <!--编码过滤器-->
    <filter>
    <filter-name>characterEncodingFilter</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>
    </filter>
    <filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--配置监听器 创建spring 对象-->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--前端控制器-->
    <servlet>
    <servlet-name>dispatcherServlet</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>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    </web-app>
  • 相关阅读:
    Seata-一站式分布式事务解决方案
    nginx相关
    module in JavaScript
    es6this箭头函数
    Python3爬虫:(一)爬取拉勾网公司列表
    markdoen语法
    吴裕雄--天生自然TensorFlow2教程:维度变换
    吴裕雄--天生自然TensorFlow2教程:numpy [ ] 索引
    吴裕雄--天生自然TensorFlow2教程:创建Tensor
    吴裕雄--天生自然TensorFlow2教程:Tensor数据类型
  • 原文地址:https://www.cnblogs.com/yxs98/p/11197820.html
Copyright © 2011-2022 走看看