私はSpring Boot以外の環境(ただしSpring 4.2)でSpring Boot Devtoolsを使用しようとしています。私はここでそれが探しているものContextListenerFileNotFoundException:ServletContextリソースを開くことができませんでした[/ <NONE>]
public class MyAppContextLoaderListener extends ContextLoaderListener
{
private static final String DEFAULT_ACTIVE_PROFILES = "";
private static final String SERVER_PROPERTIES = "jdbc/serverProperties";
private static final String SERVER_PROPERTIES_DEFAULTS = "jdbc/serverProperties-defaults";
private static final String TOMCAT_CONTEXT_NAME = "java:/comp/env/";
private static final String JETTY_CONTEXT_NAME = "";
private static final String JETTY_SERVERNAME_TOKEN = "jetty";
private static final Logger log = LoggerFactory.getLogger(MyAppContextLoaderListener.class);
private static final String SPRING_PROFILES_ACTIVE = "spring.profiles.active";
public MyAppContextLoaderListener()
{
}
public MyAppContextLoaderListener(WebApplicationContext context)
{
super(context);
}
@Override
public void contextInitialized(ServletContextEvent event) {
log.info("Starting in timezone {}...", TimeZone.getDefault().getID());
long start = System.nanoTime();
String activeProfiles = System.getProperty(SPRING_PROFILES_ACTIVE, null);
if(activeProfiles == null){
activeProfiles = lookupActiveProfiles(event);
}
log.info("Setting " + SPRING_PROFILES_ACTIVE + "=" + activeProfiles);
System.setProperty(SPRING_PROFILES_ACTIVE, activeProfiles);
super.contextInitialized(event);
log.info(String.format("started in %s Seconds.", TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start)));
}
private String lookupActiveProfiles(ServletContextEvent event)
{
String activeProfiles = DEFAULT_ACTIVE_PROFILES;
boolean isJetty = event.getServletContext().getServerInfo().contains(JETTY_SERVERNAME_TOKEN);
String name = (isJetty ? JETTY_CONTEXT_NAME : TOMCAT_CONTEXT_NAME);
Context context = null;
try
{
context = (Context) new InitialContext().lookup(name);
}
catch (NamingException ex)
{
log.error("Couldn't configure profiles from jndi", ex);
}
if (context != null)
{
try (FileReader serverPropertiesDefaults
= new FileReader(convertToFileName(context, SERVER_PROPERTIES_DEFAULTS));
FileReader serverProperties = new FileReader(convertToFileName(context, SERVER_PROPERTIES)))
{
Properties properties = new Properties();
properties.load(serverPropertiesDefaults);
properties.load(serverProperties);
activeProfiles = properties.getProperty(SPRING_PROFILES_ACTIVE, DEFAULT_ACTIVE_PROFILES);
}
catch (NamingException | IOException e)
{
log.error("Couldn't configure profiles from jndi", e);
}
}
return activeProfiles;
}
private String convertToFileName(Context context, String name) throws NamingException
{
//strip off the "file:"
return ((String)context.lookup(name)).substring(5);
}
}
だ次の例外
SEVERE: Exception sending context initialized event to listener instance of class com.myapp.spring.config.MyAppContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/<NONE>]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/<NONE>]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:510)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at com.myapp.spring.config.MyAppContextLoaderListener.contextInitialized(MyAppContextLoaderListener.java:52)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4810)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/<NONE>]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
... 22 more
Apr 18, 2016 5:11:44 PM org.apache.catalina.core.StandardContext startInternal
を取得していますか?私は私が
@EnableAutoConfiguration(exclude = JerseyAutoConfiguration.class) public class WebConfig implements WebApplicationInitializer
を追加し、このコードでは無効になっていたと思った、この入れ子になったクラス
JerseyAutoConfiguration...
@Order(Ordered.HIGHEST_PRECEDENCE)
public static final class JerseyWebApplicationInitializer
implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// We need to switch *off* the Jersey WebApplicationInitializer because it
// will try and register a ContextLoaderListener which we don't need
servletContext.setInitParameter("contextConfigLocation", "<NONE>");
}
}
を発見した
アップデートが、それはには表示されません。どうすればこの初期化子を無効にできますか?
あなたは 'com.myapp.spring.config.MyAppContextLoaderListener'のソースコードを投稿してもらえますか? –
@beckyangが追加されました – xenoterracide