@PropertySource和@ImportResource

1.@PropertySource

@ConfigurationProperties is the default Gets the specified value from the global configuration file, such as

@ConfigurationProperties (prefix = "person") this means is loaded from application.yml person or property application.properties and mapped to the corresponding attribute class

So if I write in xxx.properties of person, then it will get less than the

So this time, we have to add comments @PropertySource (value = { "classpath: xxx.properties"}) // value is a value inside the array can be multiple values

2. @ ImportResource: imported spring configuration files, such as xxx.xml

For example, I wrote a testService in bean.xml inside

<?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="testService" class="com.lyb.demo.service.testService">
    </bean>

</beans>

I then added annotations @ImportResource the application the main function (locations = { "classpath: bean.xml"})

TestService will be able to join spring container

 

Guess you like

Origin blog.csdn.net/abc_123456___/article/details/91126042