@ImportResource
2024-09-01 20:52:47
1、
@ImportResource(locations = {"classpath:beantest.xml"})标注到启动类上,从类路径下加载xml文件,通过Application.getbean获取xml配置对象
一开始写错了// @PropertySource(value = { "class:beantest.xml" })
package com.example.demo; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
@ImportResource(locations = {"classpath:beantest.xml"})
@SpringBootApplication
public class Demo2Application {
// @PropertySource(value = { "class:beantest.xml" })
public static void main(String[] args) {
SpringApplication.run(Demo2Application.class, args);
} }
bean文件
<?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="mao" class="com.example.demo.Maomao">
<property name="name" value="maomaomiaomiao"></property>
</bean> </beans>
最新文章
- gmc银联接口开发demo
- POJ3468 A Simple Problem with Integers
- php验证码无法显示的原因
- 【原】数据库SQL语句入门
- 初步学习nodejs,业余用node写个一个自动创建目录和文件的小脚本,希望对需要的人有所帮助
- bootstrap-modal.js 居中问题
- spring_boot_pay支付宝,微信,银联支付详细代码案例
- Java读写Excel之POI超入门(转)
- ArcEngine ILabelEngineLayerProperties Expression 添加常量
- Redis protected-mode属性解读
- 决策树算法原理(ID3,C4.5)
- IDEA整合Junit测试框架
- webpack的版本进化史
- 怎样将M4A音频格式转换成MP3格式
- gulp和webpack的区别
- linux修改文件所有者和文件所在组 【转载】
- 去中心化存储的QoS是什么?
- django ---- models继承
- Netty系列之Netty线程模型
- Python3.x与Python2.x的差异用法