Spring boot compatible with the old way of Spring project

There are some business scenarios, before the Spring with some of the older when writing project, but want to upgrade to Spring boot of the cost is too high, then how to do it?

By using  @ImportResource annotations to import the old configuration files (notes written in the startup class), as follows:


@SpringBootApplication
@ImportResource(locations = {"classpath:spring.xml"})
public class Application{
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

test

1. In the profile addition of the test bean:

   <bean id="testService" class="com.zsy.service.TestService"></bean>

2. Test class code:

@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTest{
	  
	@Autowired
	ApplicationContext ioc;
//判断容器中是否有testService实现类
	@Test
	public void testHelloService(){
		boolean b=ioc.containsBean("testService");
		System.out.println("容器中是否含有bean:"+b);
	}
}

3. Run Log Print:

容器是否含有bean:true

 

In this way, Spring boot can be well compatible with Spring project, can save a lot of development costs

Guess you like

Origin blog.csdn.net/syilt/article/details/92217652