2014-11-03 6 views
3

java -jar 명령을 사용하여 스프링 부트 저지 응용 프로그램을 실행할 때 문제가 있습니다. IntelliJ에서 메인 클래스를 실행할 때 잘 동작합니다. 나는 이것이 클래스 패스 문제가 될 수 있다고 가정했으나 maven-assembly-plugin을 사용했으며 모든 Spring 클래스는 거기에있는 것처럼 보인다. 스프링 부트 저지 - java -jar 명령을 실행할 때 EmbeddedServletContainerFactory가 없음

나는 한 :

<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> 
: 클래스 경로에 봄 부팅의 나머지 부분에 대한 스프링 부팅 스타터 웹, 스프링 부팅 저지, 스프링 부팅 스타터 바람둥이는 I이 포함되어있다

다음과 같이 내 조립 플러그인 구성은 : 내가 jar 파일을 추출 할 때

  <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.5</version> 
      <!-- nothing here --> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.4.1</version> 
      <configuration> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
       <archive> 
        <manifest> 
         <mainClass>org.online.auth.conf.ApplicationMain</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

나는 모든 Spring에 대한 의존성이 있다는 것을 발견 (EmbeddedServletContainer 그것은의 서브 클래스 (톰캣/부두)).

시동 로그에 다음과 같은 오류 메시지가 표시

:: Spring Boot :: 

2014-11-03 12:46:38.394 INFO 1264 --- [   main] org.online.auth.conf.ApplicationMain  : Starting ApplicationMain on R9013DA2 with PID 1264 (C:\projects\online\online-authentication-rest\target\online-authentication-rest-0.0.1-SNAPSHOT-jar-with-dependencies.jar started by thomasa in C:\projects\online\online-authentication-rest\target) 
2014-11-03 12:46:38.396 DEBUG 1264 --- [   main] o.s.boot.SpringApplication    : Loading source class com.online.auth.conf.ApplicationMain 
2014-11-03 12:46:38.412 DEBUG 1264 --- [   main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'file:./config/application.yml' resource not found 
2014-11-03 12:46:38.416 DEBUG 1264 --- [   main] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'classpath:/application.properties' 
2014-11-03 13:36:23.613 INFO 9732 --- [   main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]43738a82: startup date [Mon Nov 03 13:36:23 CET 2014]; root of context hierarchy 
2014-11-03 13:36:23.614 DEBUG 9732 --- [   main] ationConfigEmbeddedWebApplicationContext : Bean factory for org.springframework.boot[email protected]43738a82: org.s[email protected]25b485ba: 
defining beans   [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework .context.annotation.internalAutowiredAnnotationProcessor, 
org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.conte xt.annotation.internalCommonAnnotationProcessor,applicationMain]; root of factory hierarchy 

2014-11-03 13:36:23.787 INFO 9732 --- [   main]  a.ConfigurationClassBeanDefinitionReader : Skipping bean definition for  [BeanMethod:name=basicHttpCredentialsUtil,declaringClass=no.safetel.online.auth.AppConfigSpringSecur  ity]: a definition for bean 'basicHttpCredentialsUtil' already exists. 
This top-level bean definition is considered as an override. 
2014-11-03 13:36:23.873 INFO 9732 --- [   main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2014-11-03 13:36:23.888 DEBUG 9732 --- [   main] ationConfigEmbeddedWebApplicationContext : Unable to locate MessageSource with name 'messageSource': using default [[email protected]1bff] 
2014-11-03 13:36:23.888 DEBUG 9732 --- [   main] ationConfigEmbeddedWebApplicationContext : Using ApplicationEventMulticaster [org.[email protected]15bbf42f] 
2014-11-03 13:36:23.894 WARN 9732 --- [   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) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) 

내가 명시 적으로 EmbeddedServletContainerFactory을 정의하는 시도를하지만 그건 단지 A ServletContext is required to configure default servlet handling 말하는 메시지와 함께 나에게 또 다른 예외를했다.

이 문제에 대한 도움을 주시면 감사하겠습니다.

편집!

나는 모든 BeanPostProcessor를 구현하여 컨테이너에 의해 만들어진 콩 인쇄하려고 :

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 

실행 : 인 IntelliJ이 실행

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

}

을 나에게 다음과 같은 출력을 제공합니다 java 명령을 사용하는 jar 파일은 다음과 같은 결과를 출력합니다 :

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) 

도움이 될 것입니다.

답변

1

문서를 더 자세히 읽은 후에 마침내 알아 냈습니다. Spring docs에는 pom.xml의 빌드 섹션에서 spring-boot-maven-plugin을 사용해야한다고 명시되어 있습니다. 이것은 다른 사람을 위해 도움이 될 수 있습니다

<properties> 
    <start-class>org.online.auth.ApplicationMain</start-class> 
</properties> 

희망 :

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 

나는 또한 메인 클래스를 선언하는 속성을 추가했습니다.