Spring Boot Jersey-运行java-jar命令时缺少EmbeddedServletContainerFactory
我在使用Spring Boot Jersey-运行java-jar命令时缺少EmbeddedServletContainerFactory,java,maven-3,spring-boot,executable-jar,jersey-2.0,Java,Maven 3,Spring Boot,Executable Jar,Jersey 2.0,我在使用java-jar命令运行Spring Boot Jersey应用程序时遇到问题。当我从IntelliJ运行主类时,它工作得很好。因此,我假设这可能是一个类路径问题,但我使用了maven汇编插件,所有的Spring类似乎都在那里 我有: spring boot starter web、spring boot jersey、类路径上的spring boot starter tomcat以及spring boot的其余部分,我已经包括了以下内容: <dependency>
java-jar
命令运行Spring Boot Jersey应用程序时遇到问题。当我从IntelliJ运行主类时,它工作得很好。因此,我假设这可能是一个类路径问题,但我使用了maven汇编插件,所有的Spring类似乎都在那里
我有:
spring boot starter web、spring boot jersey、类路径上的spring boot starter tomcat以及spring boot的其余部分,我已经包括了以下内容:
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.1.8.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
我曾尝试显式定义EmbeddedServletContainerFactory,但这给了我另一个异常,消息说配置默认servlet处理需要一个ServletContext
在此问题上的任何帮助都将不胜感激
编辑
我试图通过实现BeanPostProcessor
来打印容器创建的每个bean:
@ComponentScan
@EnableAutoConfiguration(exclude = {
DataSourceAutoConfiguration.class,
DataSourceInitializer.class,
DataSourceTransactionManagerAutoConfiguration.class,
SecurityAutoConfiguration.class})
public class ApplicationMain extends SpringBootServletInitializer implements BeanPostProcessor {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(ApplicationMain.class, args);
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
System.out.println("\t\tbean: "+ beanName);
return bean;
}
}
在IntelliJ中运行此命令将提供以下输出:
2014-11-03 16:11:26.348 INFO 13548 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'metaDataSourceAdvisor' of type [class org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
bean: org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat
bean: tomcatEmbeddedServletContainerFactory
bean: org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
bean: org.hibernate.validator.internal.constraintvalidators.NotNullValidator
bean: serverProperties
bean: org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration
2014-11-03 16:11:26.889 INFO 13548 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-11-03 16:01:36.302 INFO 6704 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'metaDataSourceAdvisor' of type [class org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-11-03 16:01:36.310 WARN 6704 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
使用java
命令运行jar文件会得到以下输出:
2014-11-03 16:11:26.348 INFO 13548 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'metaDataSourceAdvisor' of type [class org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
bean: org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat
bean: tomcatEmbeddedServletContainerFactory
bean: org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
bean: org.hibernate.validator.internal.constraintvalidators.NotNullValidator
bean: serverProperties
bean: org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration
2014-11-03 16:11:26.889 INFO 13548 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-11-03 16:01:36.302 INFO 6704 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'metaDataSourceAdvisor' of type [class org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-11-03 16:01:36.310 WARN 6704 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
任何帮助都将不胜感激 在更彻底地阅读了文档之后,我终于找到了答案。声明明确指出,您需要在pom.xml的build部分使用SpringBootMaven插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
org.springframework.boot
springbootmaven插件
我还添加了一个声明主类的属性:
<properties>
<start-class>org.online.auth.ApplicationMain</start-class>
</properties>
org.online.auth.ApplicationMain
希望这能对其他人有所帮助