springboot 项目里使用spring.xml文件
注:启动类中得添加一个@ImportResource注解
1、beans.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:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><bean id="helloService" class="com.dc.springboot01.service.HelloService"/></beans>
2、启动类
package com.dc.springboot01;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;@SpringBootApplication
@ImportResource(locations = {"classpath:beans.xml"})
public class Springboot01Application {public static void main(String[] args) {SpringApplication.run(Springboot01Application.class, args);}}
3、测试类
package com.dc.springboot01;import com.dc.springboot01.bean.Person;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;import javax.tools.JavaFileManager;@SpringBootTest
class Springboot01ApplicationTests {//注入该属性@Autowiredprivate Person person;@Autowiredprivate ApplicationContext ac;//测试方法@Testvoid contextLoads() {// System.out.println(person);boolean flag = ac.containsBean("helloService");System.out.println(flag);}}
springboot 项目里使用spring.xml文件相关推荐
- IDEA项目创建Mapper的xml文件的方法
为了方便创建mapper的xml文件,所以可以自定义一个模板文件,以后用起来很方便. 1.打开设置 2.搜索 File and Code Templates,进行如下操作 模板代码附上 <?xm ...
- springboot项目添加了logback-spring.xml配置文件不生效
springboot,logback-spring.xml不生效 通常情况下springboot项目, 只需在src/main/resources下添加logback-spring.xml即可, lo ...
- spring-boot项目打包时候出现boot-inf文件夹的问题
1.spring-boot maven打包,一般pom.xml文件里会加<plugin><groupId>org.springframework.boot</groupI ...
- Java servlet项目里的web.xml
Created by Wang, Jerry, last modified on Jul 25, 2016 web.xml配置 <context-param> <param-name ...
- idea创建springboot项目+mybatis_从spring boot项目创建到netty项目过渡1
本文要讲解三点 1 spring boot 项目创建 2 spring boot 项目基础上面创建netty项目(下一篇) 3 netty websocket支持wss以及配置负载均衡(下一篇) No ...
- SpringBoot项目编译报错 “类文件具有错误的版本 61.0, 应为 52.0”
springboot项目在编译时报错: [INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ gulimall-cou ...
- Spring xml文件xmlns和xsi的意思
了解xml文件的同学应该都知道xml文件的验证模式保证了xml文件格式的正确性,主要的验证模式有DTD以及XSD.不过现在spring比较常用到的是xsd.以下面的例子进行一个分析: <bean ...
- 在 SpringBoot 项目中,Spring Security 和 Shiro 该如何选择?
点击上方 好好学java ,选择 星标 公众号重磅资讯,干货,第一时间送达 今日推荐:推荐19个github超牛逼项目!个人原创100W +访问量博客:点击前往,查看更多 要知道Shiro和Sprin ...
- SpringBoot+Mybatis加载Mapper.xml文件的两种方式
前言:我们在平常工作中用到mybatis去加载Mapper.xml文件,可能mapper文件放的路径不一样,由此我们需要配置多个路径,幸运的是Mybatis支持我们配置多个不同路径.现在介绍两种方法. ...
- IDEA Maven项目中,pom.xml文件显示为橘红色普通xml文件,将pom文件变为蓝色图标
一.创建Maven项目后,pom.xml显示为橘红的普通文件,可能是IDEA没有识别 二.如果可以依赖可以正常导入,文件还是显示为橘色,可能是开启了节能模式导致的 这时候取消勾选Power Save ...
最新文章
- 难以想象SpringBoot中的条件注解底层居然是这样实现的
- 关于渗透的一些思路持续更新(自我理解)
- MySQL中的组合索引
- Python实现RabbitMQ中6种消息模型(转)
- Python selenium chrome 环境配置
- IIS 常见异常及解决办法
- Eclipse 插件之间互相依赖, 导出Jar包安装, 报错“java.lang.NoClassDefFoundError”
- 计算机一级题库百度云0,全国计算机等级考试一级题库完整.pdf
- C语言:查找打印质数(素数)
- 彻底了解Windows XP操作系统登录类型
- linux里rw文件如何打开,RW 文件扩展名: 它是什么以及如何打开它?
- 安防视频监控直播的画面都是如何采集的?
- 喵哈哈村的魔法考试 Round #6 (Div.3) 题解
- android kl文件编辑,Android手机固件的简单修改教程
- 软件破解简单示例演示
- 第六期 Wiggler调试路由器 《路由器就是开发板》
- Unity HDRP中解决抗锯齿问题
- XCTF_MOBILE15_人民的名义-抓捕赵德汉1-200
- 2008年不可错过的50部好莱坞电影
- 语法体系:快速区分同位语从句和定语从句day10