ApplicationContext.xml文件,后续会代码添加,会导致代码过长,所以提供了多配制文件的开发方式

多配制文件,提供多个配置文件,有放DAO,有放Service,有放Action

上面只改动配置文件,其他类上一篇以编写

通配符方式:

把applicationContext.xml中的内容进行分解,分别创建application配置文件

applicationContext-action.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!--id:名字唯一class属性:类的全限定名通过写bean标签告诉工厂生产的对象
-->
<!--多配制文件--><!--只写Action操作--><!--    指定Action--><bean id="regAction" class="com.baizhiedu.action.Regaction" scope="prototype"><property name="userService" ref="userService"/></bean>
</beans>

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:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!--id:名字唯一class属性:类的全限定名通过写bean标签告诉工厂生产的对象
--><!--创建连接池--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/mybatis?useUnicode=true&amp;charaterEcoding=utf-8"></property><property name="username" value="root"></property><property name="password" value="123456"></property></bean><!--    创建SqlSessionFactory SqlSessionFactoryBean--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--指定数据源--><property name="dataSource" ref="dataSource"></property><!--指定类别名--><property name="typeAliasesPackage" value="com.baizhiedu.entiry"/><!--指定mapper文件--><property name="mapperLocations"><!--mapperLocations对应的是数组类型的赋值 spring内置关键字代表src--><list><value>classpath:com.baizhiedu.mapper/*Mapper.xml</value></list></property></bean><!--创建DAO对象 MapperScannerConfigure  --><bean id="confiure" class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property><property name="basePackage" value="com.baizhiedu.dao"></property></bean><!--只完成dao操作,service删掉--></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:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!--id:名字唯一class属性:类的全限定名通过写bean标签告诉工厂生产的对象
-->
<!--    多配制文件--><!--只写事务,不写dao-->
<!--    告知要创建的UserServiceImpl对象  --><bean id="userService" class="com.baizhiedu.service.UserServiceImpl"><property name="userDAO" ref="userDAO"/></bean><!-- 指定额外功能 事务--><bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean>
<!--    整合切面--><tx:annotation-driven transaction-manager="dataSourceTransactionManager"/><!--    不写action-->
</beans>

web.xml中进行:配置文件路径的编写让它可以访问所有的application配置文件:

<param-value>classpath:applicationContext-*.xml</param-value>
<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" ><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/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"metadata-complete="true"
><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><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><!--映射--><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
</web-app>

第二种方式:

import标签:

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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!--id:名字唯一class属性:类的全限定名通过写bean标签告诉工厂生产的对象
-->
<!--多配制文件--><!--只写Action操作--><!-- 多配置文件整合第二种方式--><import resource="applicationContext-action.xml"/><import resource="applicationContext-dao.xml"/><import resource="applicationContext-service.xml"/>
</beans>

在web.xml中的application配置文件的访问路径,不用改变还是写原来的

<param-value>classpath:applicationContext.xml</param-value>

再次运行:

Spring:多配制文件的使用相关推荐

  1. Spring , Spring mybatis 配制文件 模板

    2019独角兽企业重金招聘Python工程师标准>>> `### Spring , Spring mybatis 配制文件 模板 <?xml version="1.0 ...

  2. java中属性文件读取案例_java相关:Spring中属性文件properties的读取与使用详解

    java相关:Spring中属性文件properties的读取与使用详解 发布于 2020-6-3| 复制链接 摘记: Spring中属性文件properties的读取与使用详解实际项目中,通常将一些 ...

  3. php.ini 中文版第二部分(关于这个配制文件)

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 译者  :  松风(silvester)             ; ; Email :  sf.beyond@G ...

  4. spring boot 字体文件等静态资源无法获取

    spring boot 字体文件等静态资源无法获取 原因 原因maven打包时会过滤掉一些静态文件 解决办法 在pom.xml文件中配置静态资源过滤,然后再放行静态资源,这样就能让maven识别到那些 ...

  5. spring配置xml文件_XML配置文件中的Spring配置文件

    spring配置xml文件 我的上一个博客非常简单,因为它涵盖了我从Spring 3.0.x到Spring 3.1.x的轻松升级,最后我提到可以将Spring模式升级到3.1,以利用Spring的最新 ...

  6. Hibernate bean 对象配制文件

    Hibernate bean 对象配制文件 class Person{private int pid; } 1 配制主键 <?xml version="1.0" encodi ...

  7. php 忽略加载动态某个目录,限定某个目录禁止解析php 、限制user_agent 、php的配制文件、PHP的动态扩展模块...

    找到路径,然后对其进行配制: 设置时区:date.timezone 把它改成:date.timezone =Asia/Shanghai 或:date.timezone =Asia/Chongqing ...

  8. Spring简单的文件配置

    Spring简单的文件配置 "计应134(实验班) 凌豪" 一.Spring文件配置 spring至关重要的一环就是装配,即配置文件的编写,接下来我按刚才实际过程中一步步简单讲解. ...

  9. spring import resource 文件后bean找不到问题解决

    spring import resource 文件后bean找不到问题解决 参考文章: (1)spring import resource 文件后bean找不到问题解决 (2)https://www. ...

最新文章

  1. 2019年最后的一天_2019最后一天的说说 2019最后一条朋友圈再见2019
  2. java 配置dbcp_java – 配置Jetty 6以使用commons.dbcp数据源
  3. 使用Java扫描DynamoDB项目
  4. python基础之玩转(变量赋值)
  5. 内核aio_linux内核aio功能
  6. cocos2d-x之json文件读取初试
  7. python安装pygame教程_pygame 安装教程
  8. 替代 NetMeeting 的多人屏幕共享工具 InletexEMC 国外出品,永久免费
  9. labview高级视频150讲下载_Z76 谭浩强C语言视频教程48讲 | 免费下载
  10. 软件测试面试过程中常见的问题
  11. 华为 手机 能点开USB调试,退出重进再看还是关闭的
  12. 软件测试常见的风险,软件测试中常见的风险分析
  13. 如何通过云解析DNS,5步帮你实现邮箱解析
  14. 百度登录界面CSS+HTML
  15. BitBake用户手册-3.语法和操作
  16. python语言的实验心得体会范文_实验报告心得体会范文3篇_心得体会
  17. c++ 中的 LPCTSTR类型
  18. 业绩归因 绩效评估 - 各种收益率计算方法
  19. python3 base64.b64decode Base64解码报错: Incorrect padding
  20. 苹果手机iphone丢失被诈骗经历,警醒更多的人

热门文章

  1. 招商仁和青云卫2号重疾险怎么样?适不适合给小孩子配置?
  2. Linux操作之多台服务器配置免密登录
  3. Ubuntu系统设置中文
  4. RFC3581——SIP中的rport机制
  5. lucene多条件查询
  6. 基于Java+JSP+MySQL基于SSM的在线投票系统-计算机毕业设计
  7. 无U盘安装Windows系统
  8. 为什么论坛一般用PHP,关于PHPWIND与Discuz程序做论坛的一点看法
  9. 2. 输入若干个学生信息(包括学号、姓名和某科成绩),输入学号为0时输入结束,建立一个单向链表,再输入一个成绩值,将成绩大于等于该值的学生信息输出。 输入输出示例: 1 Zhang 78 2 Wang
  10. shp转化为json