[英]How I can deploy existing web applications (wars) in the Spring Boot embedded server (tomcat)
I have an application which allows to dynamically generate web applications (wars) and I would like to deploy these applications in a server to test them and I think of putting them in the same embedded server of spring, here is how I solved the problem with a simple main java.我有一个允许动态生成 web 应用程序(战争)的应用程序,我想将这些应用程序部署在服务器中以测试它们,我想将它们放在 spring 的同一嵌入式服务器中,这就是我解决问题的方法一个简单的主 java。
public class Main {
private final static Logger logger = LoggerFactory.getLogger(Main.class);
private final static File catalinaHome = new File(
"C:\\Users\\Dev\\Desktop\\demo\\userstory-2\\compiler\\patternHost");
private static Tomcat tomcat = null;
public static void main(String[] args) {
tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir(catalinaHome.getAbsolutePath());
tomcat.getHost().setAutoDeploy(true);
tomcat.getHost().setDeployOnStartup(true);
tomcat.getServer().addLifecycleListener(new VersionLoggerListener());
tomcat.getHost().addLifecycleListener(new HostConfig());
try {
tomcat.start();
} catch (LifecycleException e) {
logger.error("Tomcat could not be started.");
e.printStackTrace();
}
logger.info("Tomcat started on " + tomcat.getHost());
tomcat.getServer().await();
}
}
How can I do the same with spring boot.我怎样才能对 spring 启动做同样的事情。 ? ?
I have converted a non-spring app to spring boot in this way and it worked for me.我以这种方式将非弹簧应用程序转换为 spring 启动,它对我有用。 I was able to run it with spring boot embedded tomcat.我能够使用 spring 引导嵌入式 tomcat 运行它。 Hope this helps.希望这可以帮助。
Spring boot is all about speed, it comes with embedded-tomcat server(provided you use spring-boot-starter-web dependency) and now all you need is java to run your standalone spring boot application. Spring 启动完全与速度有关,它带有嵌入式 tomcat 服务器(前提是您使用 spring-boot-starter-web 依赖项),现在您只需要 java 即可运行您的独立 Z2A2D595E6ED9A0B24F027F4B 应用程序。 It reduces the manual steps of copying war file to tomcat's webapp folder and then starting it.它减少了将war文件复制到tomcat的webapp文件夹然后启动它的手动步骤。
Try the approach which suits your app.尝试适合您的应用的方法。
If your old app is spring based:如果您的旧应用基于 spring:
war
.修改 application.properties、resources 文件夹,在 pom.xml 文件中添加所有需要的依赖项并将 package 更改为war
。mvn clean install
it will generate a war file (with embedded tomcat) in target folder of your project's root directory.执行mvn clean install
它将在项目根目录的目标文件夹中生成一个 war 文件(带有嵌入式 tomcat)。 Now to run it all you need to do is, in your target folder open terminal and run java -jar your_warFileName.war
it will start the application.现在要运行它,您需要做的就是在目标文件夹中打开终端并运行java -jar your_warFileName.war
它将启动应用程序。If your old app is not a spring based:如果您的旧应用程序不是基于 spring 的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.