1 JavaConfig类读取properties文件
使用@PropertySource
@Configuration
@PropertySource(value = "classpath:message.properties")
public class AppConfigOne {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfigOne.class);
System.out.println(context.getEnvironment().getProperty("message"));
}
}
2 JavaConfig类引入另一个JavaConfig类
使用@Import
@Configuration
@Import(AppConfigFour.class)
public class AppConfigThree {
3 JavaConfig类引入xml配置文件
使用@ImportResource
@Configuration
@ImportResource(value="classpath:spring/app-context-xml-01.xml")
public class AppConfigFive {
提示:xml配置文件也可以引入JavaConfig类
@Configuration
public class AppConfigSix {
<context:annotation-config/>
<bean class="com.apress.prospring5.ch4.mixed.AppConfigSix"/>