1. 编写spring配置文件.xml

这里是bean.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dog" class="cn.jfjb.bean.Dog">
<property name="name" value="jjj"></property>
<property name="age" value="1233"></property>
</bean>
</beans>

bean文件

package cn.jfjb.bean;

/**
* @author john
* @date 2019/11/22 - 8:56
*/
public class Dog {
private String name;
private int age; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
} @Override
public String toString() {
return "Dog{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}

2. 在启动类中使用@ImportResource引入xml资源

package cn.jfjb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource; @SpringBootApplication
@ImportResource(locations = {"classpath:bean.xml"})
public class SbHelloworld01QuickApplication { public static void main(String[] args) {
SpringApplication.run(SbHelloworld01QuickApplication.class, args);
} }

3. 测试

package cn.jfjb.sbhelloworld01quick;

import cn.jfjb.bean.Dog;
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; @SpringBootTest
class SbHelloworld01QuickApplicationTests {
@Autowired
ApplicationContext ioc; @Autowired
Dog dog; @Test
void testImportResource(){
System.out.println(ioc.containsBean("dog"));
System.out.println(dog);
} }

springBoot2.0使用@ImportResource引入spring配置文件.xml的更多相关文章

  1. @ImportResource 导入Spring 的xml配置文件

    在配置类尚标注此注解,等同于spring配置文件中的 <import resource="beans.xml"/> Spring Boot里面没有Spring的配置文件 ...

  2. 关于Spring配置文件xml文档的schema约束

    最开始使用spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. <?xml version=&q ...

  3. eclipse spring 配置文件xml校验时,xsd报错

      1.情景展示 eclipse中,spring配置文件报错信息如下: 配置文件头部引用信息为: <?xml version="1.0" encoding="UTF ...

  4. Spring学习----- Spring配置文件xml文档的schema约束

    1.配置文件示例. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...

  5. SpringBoot2.0之三 优雅整合Spring Data JPA

      在我们的实际开发的过程中,无论多复杂的业务逻辑到达持久层都回归到了"增删改查"的基本操作,可能会存在关联多张表的复杂sql,但是对于单表的"增删改查"也是不 ...

  6. Spring配置文件XML详解

    1.bean的基本属性配置: <!-- id是bean的标识符,必须唯一,如果没有配置id,name默认为标识符 如果配置了id,有配置了name,那么name为别名 name可以设置多个别名, ...

  7. Eclipse编辑Spring配置文件xml时自动提示类class包名

    第一步,先查看下自己的Eclipse是什么版本,步骤如下: 1.1 点击Eclipse菜单‘Help  -> About Eclipse’,如下图: 1.2 点击Eclipse图标如下,看清楚哦 ...

  8. Spring 配置文件XML -- <beans>中属性概述

    beans : xml文件的根节点. xmlns : XML NameSpace的缩写,因为XML文件的标签名称都是自定义的,自己写的和其他人定义的标签很有可能会重复命名,而功能却不一样,所以需要加上 ...

  9. 2018.12.26 Mac下的Eclipse在编辑Spring配置文件xml时自动提示类class包名配置

    1.先查看下自己的Eclipse是什么版本,步骤如下: 2.选择Install New Software 3.输入网址 http://dist.springsource.com/release/TOO ...

随机推荐

  1. cogs1619. [HEOI2012]采花 x

    1619. [HEOI2012]采花 ★★☆   输入文件:1flower.in   输出文件:1flower.out   简单对比时间限制:5 s   内存限制:128 MB [题目描述] 萧薰儿是 ...

  2. ReactJS 结合 antd-mobile 开发 h5 应用基本配置

    在 ReactJS 较为初级的使用 antd-mobile 使用时候直接加载 node_modules 文件中的相关 CSS,这个使用方法效率低:更高明的方法则按需加载,需要设置如下: 在 packa ...

  3. linux crontab 定时任务,任务命令单独linux执行正常,放定时任务就不执行了,解决办法 (原)

    这是我crontab里面的内容 */30 * * * *  ./usr/bin/wget -q -O sync_log.txt http://fly.dllm.cn/index.php/Home/In ...

  4. Jmeter -- 监听 -- 查看每个请求的启动时间等信息

    步骤: 1. 添加监听器 Add --> Listener --> View Results in Table 2. 执行线程组,查看监听信息

  5. python学习之路(15)

    map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on ...

  6. ThreadPool用法与优势

    1.  线程池的优点: 合理利用线程池能够带来三个好处.第一:降低资源消耗.通过重复利用已创建的线程降低线程创建和销毁造成的消耗.第二:提高响应速度.当任务到达时,任务可以不需要等到线程创建就能立即执 ...

  7. python3笔记九:python数据类型-String字符串

    一:学习内容 字符串概念 字符串运算 字符串函数:eval().len().lower().upper().swapcase().capitalize().title().center().ljust ...

  8. HearthBuddy炉石兄弟 Method 'CollectionDeckBoxVisual.IsValid' not found.

    [CollectionManagerScene_COLLECTION] An exception occurred when calling CacheCustomDecks: System.Miss ...

  9. MySQL5.7忘记root密码-手动修改密码教程

    https://blog.csdn.net/greywolf0824/article/details/80215199

  10. linux查询端口被哪个程序使用了

    使用如下命令查询8000端口被哪个程序使用 netstat -tunlp|