[英]Spring Boot: Running as a Java application but classpath contains spring-web
I've successfully managed to create a Spring boot application that runs as a Java application as follows: 我成功地设法创建了一个作为Java应用程序运行的Spring启动应用程序,如下所示:
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication springApplication = new SpringApplication();
springApplication.setWebEnvironment(false);
springApplication.run(Application.class, args);
}
The problem is that my application requires the spring-web
module as it is a client to a REST service. 问题是我的应用程序需要
spring-web
模块,因为它是REST服务的客户端。
Once I add the spring-web
module I get an error: 一旦我添加
spring-web
模块,我收到一个错误:
Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
How can I get it to run as a Java application with spring-web
on the classpath 如何在类路径上使用
spring-web
作为Java应用程序运行它
I have "same setup" as you - command line spring boot app that uses RestTemplate
from spring-web
and everything works well. 我有“与你相同的设置” - 命令行弹簧启动应用程序,它使用来自
spring-web
RestTemplate
,一切运行良好。 Maybe it is just that I use "full" spring web starter. 也许只是我使用“全”弹簧网启动器。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
(and just slightly different main but it shouldn't be a difference) (只是略有不同的主要但它应该没有区别)
SpringApplication app = new SpringApplication(MyApplication.class);
app.setWebEnvironment(false);
app.run(args);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.