将现有的spring应用程序迁移到spring-boot,手动配置spring-boot? [英] Migrate existing spring app to spring-boot, manually configure spring-boot?

查看:111
本文介绍了将现有的spring应用程序迁移到spring-boot,手动配置spring-boot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的spring 3.1.4应用程序,可以很好地运行,并且可以自行启动.我目前在自己的主类中手动启动spring上下文.这不是spring-mvc应用程序,它不包含任何servlet,web.xml或生成WAR.它只是为集成后端生成一个JAR.

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.

我想包装"这个旧版应用程序并通过spring-boot启动它.但是,由于所有示例似乎都假设要创建一个新"应用程序,因此我很难弄清楚该怎么做.

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)我有我现有的applicationContext.xml文件,其中有我现有的spring app bean声明

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

2)为了启动带有tomcat的spring-boot并将我所有的现有bean加载到spring-boot中,我需要添加到现有Spring applicationContext.xml文件中的新bean配置的最小集合是什么?包装的上下文?

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?

推荐答案

有一章专门讨论基本上,您需要添加Spring Boot依赖项,然后实现这样的主入口点:

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

但是,这也将基于(除其他事项外)可用的类和已配置的bean触发Spring Boot的自动配置.您可能要禁用某些自动配置.要排除DataSource和Hibernate JPA自动配置,请使用:

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

这篇关于将现有的spring应用程序迁移到spring-boot,手动配置spring-boot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆