SpringBoot底层注解@ImportResource导入Spring配置文件

实体类:

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Pat {
    private String name;
    private Integer age;
}

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class User {
    private String name;
    private Integer age;
    private Pat pat;

    public User(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
}

spring配置文件:




    
        
        
    

    
        
        
    

配置类:

// 导入上面的xml配置文件
@ImportResource("classpath:beans.xml")
public class MyConfig {
    // ...
}

启动类测试:

boolean hello = run.containsBean("hello");
boolean world = run.containsBean("world");
System.out.println("hello:" + hello);// true
System.out.println("world:" + world);// true

雷丰阳2021版SpringBoot2零基础入门springboot全套完整版(spring boot2)

 

 

你可能感兴趣的:(Java,spring,boot,spring,java)