public class TestServiceImpl implements ITestService{ @Override public void test() { System.out.println("TestServiceImpl.test()"); } }
接口spring
public interface ITestService { public void test(); }
application-bean.xmlspring-mvc
<?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>
引入xmlspringboot
@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); } }
調用mvc
@Resource(name="testService") private ITestService testService;