Where do I put my XML beans in a Spring Boot application?

后端 未结 3 819
小鲜肉
小鲜肉 2020-12-23 22:47

I\'m getting back into Spring (currently v4). It\'s all wonderful now with @SpringBootApplication and the other annotations but all the documentation seems to f

3条回答
  •  难免孤独
    2020-12-23 23:41

    Spring boot ideal concept is avoid xml file. but if you want to keep xml bean, you can just add @ImportResource("classPath:beanFileName.xml").

    I would recommend remove the spring-sftp-config.xml file. And, convert this file to spring annotation based bean. So, whatever class has been created as bean. Just write @Service or @Component annotation before class name. for example:

    XML based:

    
    

    Annotation:

    @Service or @Component
    class Employee{
    }
    

    And, add @ComponentScan("Give the package name"). This is the best approach.

提交回复
热议问题