Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

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

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 a spring-mvc app, it does not contain any servlets, web.xml nor does it generate a WAR. It just produces a JAR for an integration backend.

I would like "wrap" this legacy application and launch it with spring-boot. However I am having trouble figuring out how to do this as all the examples seem to assume creating a "new" application.

1) I have my existing applicationContext.xml file with my existing spring app bean declarations in it

2) What is the minimum set of new bean configs that I need to add to my existing Spring applicationContext.xml file in order to have spring-boot w/ tomcat launched and load all of my existing beans into the spring-boot wrapped context?

Can anyone point me in the right direction please?

question from:https://stackoverflow.com/questions/31409231/migrate-existing-spring-app-to-spring-boot-manually-configure-spring-boot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...