SpringBoot23 之 导入XML配置
来源:互联网 发布:飞扬软件官网 编辑:程序博客网 时间:2024/06/05 11:20
1.新建一个maven工程
2.创建Springboot项目
3创建包
4创建Service
Spring Boot理念就是零配置编程,但是如果绝对需要使用XML的配置,我们建议您仍旧从一个@Configuration类开始,你可以使用@ImportResouce注解加载XML配置文件,我拿一个例子来进行讲解:
这个例子的大体步骤如下:
(1)新建一个工程;
(2)在App.java类编写HelloService2;
(3)在App.java类无法扫描的包下编写HelloService;
(4)编写application-bean.xml注入HelloService;
(5)编写ConfigClass注入配置文件application-bean.xml;
(6)编写App.java启动类进行测试;
(7)其它说明
@Servicepublic class HelloService { public HelloService(){ System.out.print("helloServiceto1"); }}@Servicepublic class HelloService2 { public HelloService2(){ System.out.print("helloServiceto2"); }}
5.创建配置类
@Configuration@ImportResource(locations={"classpath:application-bean.xml"})public class config {}
配置文件application-bean.xml在src/main/resource下
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="helloService" class="com.test.service.HelloService"></bean></beans>
0 0
- SpringBoot23 之 导入XML配置
- spring boot导入xml配置
- spring XML配置导入不了properties文件
- 第二十五章 SpringBoot导入XML配置
- Spring Boot 学习22--导入XML配置
- Mybatis之XML配置
- Solr DataImportHandler 之二 XML/http导入
- Java解析XML之导入dom4j
- 导入XML
- maven2配置之pom.xml
- mcat配置之server.xml
- web.xml之Servlet配置
- web.xml之配置Struts
- SSH配置之web.xml
- SSH配置之web.xml .
- springmvc之web.xml配置
- Tomcat配置之content.xml
- SSH配置之web.xml .
- bit和byte以及千字节关系
- Visual Studio配置(2):项目属性页-常规
- webuploader 使用心得 -2 接口说明
- oracle行列转换
- 修改反编译插件的源码
- SpringBoot23 之 导入XML配置
- 面试5
- IDEA下从零开始搭建SpringBoot工程
- leecode 解题总结:98. Validate Binary Search Tree
- 整理的一些swift开源项目,仅供学习交流!!
- javascript基础(事件的传播)(三十五)
- N 皇后问题 : Leetcode 51. N-Queens
- html固定表头
- hadoop 集群优化