@PropertySource&@ImportResource&@Bean

@PropertySource: " Load specified profile: @PropertySource (value = {" classpath : person.properties "})

 

@ImportResource: Import allowed to take effect profile Spring @ImportResource (locations = { "classpath: beans.xml"})

Spring Boot there is no Spring configuration file, write our own configuration files, it can not automatically identify;

Would like Spring configuration file to take effect, came loaded; @ImportResource marked on a configuration class

Add SpringBoot Tell container assembly; recommended approach full annotations
1, configuration class @Configuration ------> Spring profile
2, use @Bean add components to a container

/ **
* @Configuration: specified the current configuration class is a class; that is, before the Spring configuration file to replace

* In the configuration file with <bean> <bean /> tag add components
*
* /

@Configuration
public class MyAppConfig {
// the return value is added to the vessel; container id this component is the default method name
@Bean
public the HelloService helloService02 () {
System.out.println ( "class configuration to a container @Bean Add components of ... ");
return the HelloService new new ();
}



Guess you like

Origin www.cnblogs.com/banml/p/11390550.html