springBoot2.0使用@ImportResource引入spring配置文件.xml
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的更多相关文章
- @ImportResource 导入Spring 的xml配置文件
在配置类尚标注此注解,等同于spring配置文件中的 <import resource="beans.xml"/> Spring Boot里面没有Spring的配置文件 ...
- 关于Spring配置文件xml文档的schema约束
最开始使用spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. <?xml version=&q ...
- eclipse spring 配置文件xml校验时,xsd报错
1.情景展示 eclipse中,spring配置文件报错信息如下: 配置文件头部引用信息为: <?xml version="1.0" encoding="UTF ...
- Spring学习----- Spring配置文件xml文档的schema约束
1.配置文件示例. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- SpringBoot2.0之三 优雅整合Spring Data JPA
在我们的实际开发的过程中,无论多复杂的业务逻辑到达持久层都回归到了"增删改查"的基本操作,可能会存在关联多张表的复杂sql,但是对于单表的"增删改查"也是不 ...
- Spring配置文件XML详解
1.bean的基本属性配置: <!-- id是bean的标识符,必须唯一,如果没有配置id,name默认为标识符 如果配置了id,有配置了name,那么name为别名 name可以设置多个别名, ...
- Eclipse编辑Spring配置文件xml时自动提示类class包名
第一步,先查看下自己的Eclipse是什么版本,步骤如下: 1.1 点击Eclipse菜单‘Help -> About Eclipse’,如下图: 1.2 点击Eclipse图标如下,看清楚哦 ...
- Spring 配置文件XML -- <beans>中属性概述
beans : xml文件的根节点. xmlns : XML NameSpace的缩写,因为XML文件的标签名称都是自定义的,自己写的和其他人定义的标签很有可能会重复命名,而功能却不一样,所以需要加上 ...
- 2018.12.26 Mac下的Eclipse在编辑Spring配置文件xml时自动提示类class包名配置
1.先查看下自己的Eclipse是什么版本,步骤如下: 2.选择Install New Software 3.输入网址 http://dist.springsource.com/release/TOO ...
随机推荐
- sh_04_列表排序
sh_04_列表排序 name_list = ["zhangsan", "lisi", "wangwu", "wangxiaoer ...
- pip安装源和虚拟环境的搭建
一.pip安装源 1.介绍 采用国内源,加速下载模块的速度 常用pip源: 豆瓣:https://pypi.douban.com/simple 阿里:https://mirrors.aliyun.co ...
- unittest详解(七) 自动生成测试报告
用例执行完成后,执行结果默认是输出在屏幕上,其实我们可以把结果输出到一个文件中,形成测试报告. unittest自带的测试报告是文本形式的,如下代码: import unittest if __nam ...
- Linux任务计划及周期性任务执行:at、crontab命令
一.概述 未来的某时间点执行一次某任务:at, batch 周期性运行某任务:crontab 这两个任务的执行结果:会通过邮件发送给用户 (本地终端用户之间的邮件通知) centos 5,6,7默认开 ...
- JS框架_(JQuery.js)网页文字评论弹幕
百度云盘 传送门 密码:3azl jQuery网页右下角文字评论弹幕效果 <!DOCTYPE html> <html> <head> <title>jQ ...
- JDBC连接数据库遇到的“驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。
要从旧算法列表中删除3DES: 在JDK 8及更早版本中,编辑该 /lib/security/java.security文件并3DES_EDE_CBC从jdk.tls.legacyAlgorithms ...
- JSP——指令(Directive)
指令是一种JSP句法元素,它告诉JSP转换器应该如何将某个JSP页面转换成Servlet. JSP 2.2中定义了几个指令:page.include.taglib.tag.attribute以及var ...
- leetcode-easy-listnode-234 Palindrome Linked List
mycode 89.42% # Definition for singly-linked list. # class ListNode(object): # def __init__(self, ...
- leetcode 102二叉树的层序遍历
5月20更新: 使用借助队列实现bfs,定义len记录队列的尺寸直接进行遍历层序 /** * Definition for a binary tree node. * struct TreeNode ...
- org-mode 写 cnblogs 博客
1. 为什么用org-mode写博客 我最开始用Emacs, 是因为org-mode.这是一个专注于写,而让我忽略展示结果的一种写作方式.为 什么这么说?因为所有内容的格式都是可定制的.按照自己喜欢的 ...