2015-06-05 56 views
0

我使用WebAppContext作爲嵌入式碼頭的處理程序:碼頭開始與java.lang.IllegalArgumentException異常:資源不能爲null

Server server = setupServerOfTwoConnectors(); 
server.setHandler(webAppContext()); 

server.start(); 

而且webAppContext()是:

private static WebAppContext webAppContext() { 
    WebAppContext context = new WebAppContext(); 
    context.setContextPath("/foo"); 
    context.setWar("bar.war"); 

    return context; 
} 

我是否這裏錯過了什麼? 該碼頭的版本是9.2.10.v20150310

這是例外啓動時:

2015-06-05 10:57:45,015 [main] ERROR - [ContextLoader:331] Context initialization failed 
java.lang.IllegalArgumentException: Resource must not be null 
    at org.springframework.util.Assert.notNull(Assert.java:112) 
    at org.springframework.core.io.support.EncodedResource.<init>(EncodedResource.java:66) 
    at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175) 
    at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156) 
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:80) 
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265) 
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162) 
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) 
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800) 
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444) 
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791) 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294) 
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349) 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342) 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) 
    at org.eclipse.jetty.server.Server.start(Server.java:387) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) 
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) 
    at org.eclipse.jetty.server.Server.doStart(Server.java:354) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at my.code.JettySanityTest.setupJetty(JettySanityTest.java:56) 
+1

一些調試後,我發現的根本原因是在VM參數 –

回答

0

不知道你的war文件從碼頭的配置需要我只是採取刺傷在黑暗這個答案。 (相應地進行調整)

您需要聲明該webapp的一些配置行爲。

如:

context.setConfigurations(new Configuration[] 
    { 
     new AnnotationConfiguration(), 
     new WebInfConfiguration(), 
     new WebXmlConfiguration(), 
     new MetaInfConfiguration(), 
     new FragmentConfiguration(), 
     new EnvConfiguration(), 
     new PlusConfiguration(), 
     new JettyWebXmlConfiguration() 
    }); 

注意的是,這些順序很重要,任何人可以考慮選購。

  • AnnotationConfiguration -
  • WebXmlConfiguration(通過啓用了WEB-INF目錄上配置從信息的web應用(主要Web應用程序和庫的) - 中存在的字節碼註釋
  • WebInfConfiguration(默認啓用)配置Web應用程序默認) - 根據WEB-INF/web.xml中的信息配置webapp元數據(僅適用於主webapp)
  • MetaInfConfiguration(默認啓用) - 在META-INF目錄上配置從信息的web應用
  • FragmentConfiguration(默認啓用)(主web應用和庫的) - 配置從信息的web應用的元數據存在於LIB片段
  • EnvConfiguration - 設置一個JNDI ENV用於web應用
  • PlusConfiguration - 建立基於從上述配置
  • JettyWebXmlConfiguration(默認啓用)在元數據中收集的信息/綁定JNDI變量 - configur從主要的Web應用程序的WEB-INF/jetty-web.xml(使用碼頭的IoC XML語言)在線web應用
+0

感謝您抽出寶貴的時間來回答這個問題缺少'-D'配置。我發現問題的根本原因(請參閱問題中的評論) –

相關問題