Migrate existing spring app to spring-boot, manually configure spring-boot?

后端 未结 1 1819
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 04:00

I have an existing spring 3.1.4 application that works fine and boots up ok on its own. I currently start the spring context manually in a main class of my own. This is NOT

1条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 04:41

    There is a chapter dedicated to Converting an existing application to Spring Boot in the Spring Boot reference guide.

    Basically you need to add the Spring Boot dependencies and then implement the main entry point like this:

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

    However, this will also trigger Spring Boot's auto-configuration based upon (among other things) available classes and configured beans. You might want to disable certain auto-configurations. To exclude DataSource and Hibernate JPA auto-configuration, use:

    @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
    

    0 讨论(0)
提交回复
热议问题