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>

  

@ImportResource的更多相关文章

  1. spring源码分析之@ImportSelector、@Import、ImportResource工作原理分析

    1. @importSelector定义: /** * Interface to be implemented by types that determine which @{@link Config ...

  2. spring @import和@importResource

    @ImportResource in spring imports application xml in configuration file which is using @Configuratio ...

  3. SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-008-在Java配置文件中引入xml配置文件@Import、@ImportResource

    1. package soundsystem; import org.springframework.beans.factory.annotation.Autowired; public class ...

  4. Spring学习(14)--- 基于Java类的配置Bean 之 @ImportResource & @Value 注解

    学习如何使用@ImportResource 和 @Value 注解进行资源文件读取 例子: 先创建一个MyDriverManager类(模拟读取数据库配置信息) package com.beanann ...

  5. SpringBoot入门教程(十八)@value、@Import、@ImportResource、@PropertySource

    Spring Boot提倡基于Java的配置.这两篇博文主要介绍springboot 一些常用的注解介绍 v@value 通过@Value可以将外部的值动态注入到Bean中. 添加applicatio ...

  6. 学习 Spring (十) 注解之 @Bean, @ImportResource, @Value

    Spring入门篇 学习笔记 @Bean @Bean 标识一个用于配置和初始化一个由 Spring IoC 容器管理的新对象的方法,类似于 XML 配置文件的 可以在 Spring 的 @Config ...

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

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

  8. Spring 学习——Spring常用注解——@Component、@Scope、@Repository、@Service、@Controller、@Required、@Autowired、@Qualifier、@Configuration、@ImportResource、@Value

    Bean管理注解实现 Classpath扫描与组件管理 类的自动检测与注册Bean 类的注解@Component.@Service等作用是将这个实例自动装配到Bean容器中管理 而类似于@Autowi ...

  9. 尚硅谷springboot学习10-@PropertySource,@ImportResource,@Bean

    @PropertySource 使用指定的属性文件而不一定是application.xxx 同样可以注入相关内容 @ImportResource 导入Spring的配置文件,让配置文件里面的内容生效: ...

  10. SpringBoot开发使用@ImportResource注解影响拦截器

    问题描述 今天在给SpringBoot项目配置拦截器的时候发现怎么都进不到拦截器的方法里面,在搜索引擎上看了无数篇关于配置拦截器的文章都没有找到解决方案. 就在我准备放弃的时候,在 CSDN 上发现了 ...

随机推荐

  1. ansible批量管理常见的配置方法

    第7章 ansible的管理 7.1 ansible概念的介绍 ansible-playbook –syntax            检查语法 ansible-playbook -C         ...

  2. vbs 脚本 获取机器名/IP/MAC

    strComputer = "."strMesseage="" Set objWMIService = GetObject("winmgmts:{im ...

  3. python爬虫--爬虫与反爬

    爬虫与反爬 爬虫:自动获取网站数据的程序,关键是批量的获取. 反爬虫:使用技术手段防止爬虫程序的方法 误伤:反爬技术将普通用户识别为爬虫,从而限制其访问,如果误伤过高,反爬效果再好也不能使用(例如封i ...

  4. java基础篇一

    引言 本人系南京一小小学校的大三小小菜鸟,三年来学了很多杂七杂八的,也荒废了大量的时间,马上就要秋招了,之前也看了不少面试题,备选了一些简单的项目,看了不知多少本的几百页厚的各种知识的pdf电子书,发 ...

  5. vue之新手使用

    vue中文网站:https://cn.vuejs.org/v2/guide/installation.html  包含了安装.使用.api.视频. 一. 什么是 Vue Vue 是一个前端框架,特点是 ...

  6. AQS系列(四)- ReentrantReadWriteLock读写锁的释放锁

    前言 继续JUC包中ReentrantReadWriteLock的学习,今天学习释放锁. 一.写锁释放锁 入口方法 public void unlock() { sync.release(1); } ...

  7. 使用Future

    /** * Runnable接口有个问题,它的方法没有返回值.如果任务需要一个返回结果,那么只能保存到变量,还要提供额外的方法读取,非常不便. * Java标准库还提供了一个Callable接口,和R ...

  8. Java实现微信小程序支付(完整版)

    在开发微信小程序支付的功能前,我们先熟悉下微信小程序支付的业务流程图: 不熟悉流程的建议还是仔细阅读微信官方的开发者文档. 一,准备工作 事先需要申请企业版小程序,并开通“微信支付”(即商户功能).并 ...

  9. WinForm WebBrowser 设置cookie

    [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] public static exte ...

  10. python基础之列表讲解

    列表是最常用的Python数据类型,它可以作为一个方括号内的逗号分隔值出现. 列表的数据项不需要具有相同的类型 如下图所示,创建一个列表,只要把逗号分隔的不同的数据项使用方括号括起来即可.(接下来的演 ...