@ImportResource
@ImportResource
**作用:**导入spring中的xml配置文件,使得配置中的文件生效
例子代码如下:
@ImportResource(locations = "classpath:test.xml")
@SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}
package com.example.demo.pojo;public class People {private String Pname;private int age;public String getPname() {return Pname;}public void setPname(String pname) {Pname = pname;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}}
package com.example.demo.controller;import com.example.demo.pojo.People;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class ControllerOne {@AutowiredPeople p;@RequestMapping("/one")public People getP(){return p;}
}
【注】 xml文件放置的位置,之后代码在不同服务器上运行时,必须使用classpath,否则无法找到文件位置
结果:
@ImportResource相关推荐
- SpringBoot复习:4(@ImportResource)
@ImportResource注解 作用:这个注解可以用来导入Spring的配置文件(bean.xml文件). 适用场景: 可以试想一下这样一个场景,老板要你将原来的Spring项目改成SpringB ...
- @ImportResource SpringBoot使用xml配置Bean
前言 SpringBoot推荐使用注解的方式去声明bean,但还是提供了xml的方式去加载bean 一.创建要声明为bean的实体类 WzqEntity.java package com;/** * ...
- php import_resource,@ImportResource
1. @ImportResource(locations = {"classpath:beantest.xml"})标注到启动类上,从类路径下加载xml文件,通过Applicati ...
- Spring@Configuration、@Bean、@Import 、@ImportResource、@DependsOn 说明
为什么80%的码农都做不了架构师?>>> 使用spring的这几个配置,可以将旧<xml>配置形式完全使用Java实现,也可以和<xml>嵌套使用. @ ...
- @PropertySource@ImportResource@Bean
@PropertySource&@ImportResource&@Bean @PropertySource:加载指定的配置文件: @ConfigurationProperties(p ...
- spring源码分析之@ImportSelector、@Import、ImportResource工作原理分析
1. @importSelector定义: /*** Interface to be implemented by types that determine which @{@link Configu ...
- Spring的@ImportResource注解
@ImportResource 导入Spring的配置文件 让配置文件里面的内容生效 使用方式 标注在一个配置类上 @ImportResource(locations = {"classpa ...
- SpringBoot中@PropertySource和@ImportResource以及@Bean
@PropertySource 加载指定的配置文件 只能加载*.properties文件,不能加载yaml文件 新建一个user.properties user.nickname=张三 user.ag ...
- SpringBoot底层注解-@ImportResource导入Spring配置文件
======================beans.xml========================= <?xml version="1.0" encoding=& ...
最新文章
- How to enable coredump on centos 7.6
- CSS实例:图片导航块
- hibernate by example 排除某些列
- nginx配置文件【转载】
- discuz!5.5.0安装方法及常见问题解决
- 奥的斯服务器状态显示,奥的斯电梯调试服务器(俗称st)按键介绍
- mysql 逻辑备份 物理备份_数据库的逻辑备份和物理备份--非RMAN
- java书面_Java程序猿的书面采访String3
- java将数据流解析为字符串
- 如何在aspx页面中插入swf动画
- Hash算法大全(java实现)
- linux查看服务_Linux服务下通过指令查看JVM(非原创侵删)
- 【电子科技大学-微电子技术导论】学习笔记
- js代码混淆 webpack-obfuscator
- 计算机操作系统试题题库及答案(完整版)
- cl.exe nmake.exe
- java 龟兔赛跑_Java实现多线程模拟龟兔赛跑
- 经典算法系列之不死神兔
- 人脸识别篇---人脸对齐
- 刷题_25:星际密码 and 数根