spring-boot 引入xml注入bean

spring-boot 引入xml注入bean

配置

public class TestServiceImpl implements ITestService{
	@Override
	public void test() {
		System.out.println("TestServiceImpl.test()");
	}
}

接口

public interface ITestService {
	public void test();
}

application-bean.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd  
            http://www.springframework.org/schema/context  
            http://www.springframework.org/schema/context/spring-context.xsd  
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc.xsd">
	<!-- 测试引用xml -->
	<bean id="testService" class="com.maple.test.service.impl.TestServiceImpl"/>
</beans>

引入xml

@SpringBootApplication
@ServletComponentScan
@Import(value={SpringUtil.class})
@ComponentScan(basePackages={"com.maple.springboot","com.maple.testpackage"})
//引入xml配置
@ImportResource(locations={"classpath:config/application-bean.xml"})
@EnableConfigurationProperties({CustomSettings.class,MapleSettings.class})
public class App {
	
	public static void main(String[] args) {
		
		//配置banner
		SpringApplication application = new SpringApplication(App.class);
		application.setBannerMode(Banner.Mode.OFF);
		application.run(args);

	}
}

调用

@Resource(name="testService")
private ITestService testService;

猜你喜欢

转载自my.oschina.net/u/159221/blog/1621988