我正在尝试按照他们的文档从 Spring Boot 应用程序创建可部署的 *.war。我在扩展 SpringBootServletInitializer 时遇到问题。它给了我一个编译时错误说The type org.springframework.web.WebApplicationInitializer cannot be resolved. It is indirectly referenced from required .class files
。但是在 Maven 依赖目录中我可以清楚地看到SpringBootServletInitializer.class
存在于spring-boot-1.5.10.RELEASE
jar 中。它是作为camel-spring-boot-starter
依赖项的一部分下载的。
我的主课
@SpringBootApplication
@EnableAutoConfiguration
public class SpringCamelApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(SpringCamelApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringCamelApplication.class);
}
@Bean
public RestConfiguration restConfiguration()
{
RestConfiguration restconfig=new RestConfiguration();
restconfig.setPort(8081);
restconfig.setComponent("restlet");
//restconfig.setHost("localhost");
restconfig.setContextPath("/api");
restconfig.setBindingMode("auto");
return restconfig;
}
}
我的 pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.camel</groupId>
<artifactId>spring-camel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-camel</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<camel.version>2.21.0</camel.version>
<spring.version>2.0.0.RELEASE</spring.version>
<start-class>com.camel.springcamel.SpringCamelApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<version>${camel.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我在哪里错了?我注意到如果我使用spring-boot-starter-web
依赖项,那么这不会给我任何错误,但我已经有了camel-spring-boot-starter
,所以我不应该需要spring-boot-starter-web
. 谁能解释这里到底出了什么问题?提前致谢。