Spring boot 运行时出现Spring cloud Eureka错误

Spring boot 运行时出现Spring cloud Eureka错误,spring-boot,spring-cloud,Spring Boot,Spring Cloud,我正在尝试使用下面的pom创建一个SpringCloud Eureka服务器,它主要源于 但是,我得到了“创建名为'viewControllerHandlerMapping'的bean时出错”的错误,这是由“java.lang.IllegalStateException:如果资源当前未启动,则可能无法访问”引起的 我认为这可能与拉取的各种Jersey组件的版本1.11和1.13有关,尽管我没有看到任何一个jar被拉取两次。除此之外,我不知道为什么。有什么想法吗?提前谢谢 <project

我正在尝试使用下面的pom创建一个SpringCloud Eureka服务器,它主要源于

但是,我得到了“创建名为'viewControllerHandlerMapping'的bean时出错”的错误,这是由“java.lang.IllegalStateException:如果资源当前未启动,则可能无法访问”引起的

我认为这可能与拉取的各种Jersey组件的版本1.11和1.13有关,尽管我没有看到任何一个jar被拉取两次。除此之外,我不知道为什么。有什么想法吗?提前谢谢

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.my.cloudconfig</groupId>
  <artifactId>eureka</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>eureka</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka-server</artifactId>
      <version>1.0.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.2.7</version>
      </plugin>
    </plugins>
  </build>

</project>
堆栈跟踪:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewControllerHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'viewControllerHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: The resources may not be accessed if they are not currently started
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
    at com.my.cloudconfig.EurekaApplication.main(EurekaApplication.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'viewControllerHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: The resources may not be accessed if they are not currently started
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 22 more
Caused by: java.lang.IllegalStateException: The resources may not be accessed if they are not currently started
    at org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:245)
    at org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:212)
    at org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:206)
    at org.apache.catalina.core.ApplicationContext.getResource(ApplicationContext.java:553)
    at org.apache.catalina.core.ApplicationContextFacade.getResource(ApplicationContextFacade.java:199)
    at org.springframework.web.context.support.ServletContextResource.exists(ServletContextResource.java:102)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.addStaticIndexHtmlViewControllers(WebMvcAutoConfiguration.java:276)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.addViewControllers(WebMvcAutoConfiguration.java:271)
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.addViewControllers(WebMvcConfigurerComposite.java:119)
    at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.addViewControllers(DelegatingWebMvcConfiguration.java:77)
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.viewControllerHandlerMapping(WebMvcConfigurationSupport.java:346)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3f1ec1c2.CGLIB$viewControllerHandlerMapping$25(<generated>)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3f1ec1c2$$FastClassBySpringCGLIB$$722e1019.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3f1ec1c2.viewControllerHandlerMapping(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 23 more
线程“main”org.springframework.beans.factory.BeanCreationException中的异常:创建名为“viewControllerHandlerMapping”的bean时出错,该名称在类路径资源[org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]中定义:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.beans实例化异常:未能实例化[org.springframework.web.servlet.HandlerMapping]:工厂方法“viewControllerHandlerMapping”引发异常;嵌套异常为java.lang.IllegalStateException:如果资源当前未启动,则可能无法访问它们
位于org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:599)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
位于org.springframework.beans.factory.support.DefaultListableBeanFactory.PreInstanceSingleton(DefaultListableBeanFactory.java:755)
位于org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
位于org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
位于org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
位于org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
位于com.my.cloudconfig.EurekaApplication.main(EurekaApplication.java:18)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:497)
位于com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
原因:org.springframework.beans.beans实例化异常:未能实例化[org.springframework.web.servlet.HandlerMapping]:工厂方法“viewControllerHandlerMapping”引发异常;嵌套异常为java.lang.IllegalStateException:如果资源当前未启动,则可能无法访问它们
位于org.springframework.beans.factory.support.SimpleInstallationStrategy.instantiate(SimpleInstallationStrategy.java:189)
位于org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:588)
... 还有22个
原因:java.lang.IllegalStateException:如果资源当前未启动,则可能无法访问它们
位于org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:245)
在org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:212)上
位于org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:206)
位于org.apache.catalina.core.ApplicationContext.getResource(ApplicationContext.java:553)
位于org.apache.catalina.core.ApplicationContextFacade.getResource(ApplicationContextFacade.java:199)
位于org.springframework.web.context.support.ServletContextResource.exists(ServletContextResource.java:102)
位于org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.addStaticIndexHtmlViewControllers(WebMvcAutoConfiguration.java:276)
位于org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.addViewController(WebMvcAutoConfiguration.java:271)
位于org.springframework.web.servlet.config.annotation.webmvcconfigurecomposite.addViewController(webmvcconfigurecomposite.java:119)
位于org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.addViewControllers(DelegatingWebMvcConfiguration.java:77)
位于org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.viewControllerHandlerMapping(WebMvcConfigurationSupport.java:346)
在org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3f1ec1c2.CGLIB$viewControllerHandlerMapping$25()
在org.springframework.boot.autoconfigure.web上。
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewControllerHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'viewControllerHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: The resources may not be accessed if they are not currently started
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
    at com.my.cloudconfig.EurekaApplication.main(EurekaApplication.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'viewControllerHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: The resources may not be accessed if they are not currently started
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 22 more
Caused by: java.lang.IllegalStateException: The resources may not be accessed if they are not currently started
    at org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:245)
    at org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:212)
    at org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:206)
    at org.apache.catalina.core.ApplicationContext.getResource(ApplicationContext.java:553)
    at org.apache.catalina.core.ApplicationContextFacade.getResource(ApplicationContextFacade.java:199)
    at org.springframework.web.context.support.ServletContextResource.exists(ServletContextResource.java:102)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.addStaticIndexHtmlViewControllers(WebMvcAutoConfiguration.java:276)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.addViewControllers(WebMvcAutoConfiguration.java:271)
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.addViewControllers(WebMvcConfigurerComposite.java:119)
    at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.addViewControllers(DelegatingWebMvcConfiguration.java:77)
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.viewControllerHandlerMapping(WebMvcConfigurationSupport.java:346)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3f1ec1c2.CGLIB$viewControllerHandlerMapping$25(<generated>)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3f1ec1c2$$FastClassBySpringCGLIB$$722e1019.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3f1ec1c2.viewControllerHandlerMapping(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 23 more
[INFO] |  +- org.springframework.cloud:spring-cloud-netflix-eureka-server:jar:1.0.3.RELEASE:compile
[INFO] |  |  +- com.netflix.eureka:eureka-client:jar:1.1.147:compile
[INFO] |  |  |  +- com.sun.jersey:jersey-core:jar:1.11:compile
[INFO] |  |  |  +- com.sun.jersey:jersey-client:jar:1.11:runtime
[INFO] |  |  |  +- com.sun.jersey.contribs:jersey-apache-client4:jar:1.11:runtime
[INFO] |  |  +- com.sun.jersey:jersey-servlet:jar:1.13:compile
[INFO] |  |  +- com.sun.jersey:jersey-server:jar:1.13:compile
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-eureka-server</artifactId>
  <version>1.0.3.RELEASE</version>
  <exclusions>
    <exclusion>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-servlet</artifactId>
    </exclusion>
    <exclusion>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-server</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-servlet</artifactId>
  <version>1.11</version>
</dependency>

<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-server</artifactId>
  <version>1.11</version>
</dependency>