【问题标题】:Unable to start springboot app - Resource location must not be null无法启动 Spring Boot 应用程序 - 资源位置不能为空
【发布时间】:2016-11-14 09:02:52
【问题描述】:

第一次尝试 springboot 但我无法启动它。 我使用了示例应用程序:https://github.com/spring-guides/gs-spring-boot.git 我还进行了修改以使用嵌入式码头而不是 tomcat,但仍然没有成功。

我得到的异常是:org.springframework.context.ApplicationContextException:无法启动嵌入式容器;嵌套异常是 java.lang.IllegalArgumentException: Resource location must not be null.

这是在 MacOSX 上。

编辑:我已经确认这是一个环境问题。我可以在 linux(fedora) VM 中很好地启动应用程序,但无论出于何种原因,我在我的 Mac 上遇到了这个问题。不知道是否有其他人遇到过这种情况,并且对可能导致这种情况的原因有任何线索。

编辑 2:所以这似乎是尝试默认配置 ssl 的问题。我不确定为什么会这样,因为我没有在任何地方指定这个;所以我现在的问题是,如何在 spring-boot 中禁用 https?

mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T09:29:23-08:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.5", arch: "x86_64", family: "mac"

感谢任何帮助。

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.IllegalArgumentException: Resource location must not be null
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at hello.Application.main(Application.java:15) [classes!/:0.1.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [gs-spring-boot-0.1.0.jar:0.1.0]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [gs-spring-boot-0.1.0.jar:0.1.0]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [gs-spring-boot-0.1.0.jar:0.1.0]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [gs-spring-boot-0.1.0.jar:0.1.0]
Caused by: java.lang.IllegalArgumentException: Resource location must not be null
    at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
    at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:131) ~[spring-core-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.configureSslKeyStore(TomcatEmbeddedServletContainerFactory.java:417) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.configureSsl(TomcatEmbeddedServletContainerFactory.java:395) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.customizeSsl(TomcatEmbeddedServletContainerFactory.java:332) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.customizeConnector(TomcatEmbeddedServletContainerFactory.java:311) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:169) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    ... 16 common frames omitted

【问题讨论】:

  • 请粘贴整个堆栈跟踪
  • 堆栈跟踪显示您的应用仍在使用 Tomcat。看起来您正在尝试配置 SSL,但配置不完整。重现问题的完整示例将更容易弄清楚发生了什么。
  • 同意@AndyWilkinson 在嵌入式服务器上仍然是tomcat而不是Jetty。我试图在这里找到 spring-core 依赖项的根异常“资源位置不能为空” - github.com/spring-projects/spring-framework/blob/v4.3.4.RELEASE/… 行 - 131。您的应用似乎丢失了(一些必要的!?)类路径中的资源。希望您知道如何从那里解决它。
  • @AndyWilkinson 堆栈跟踪是在我进行任何更改以使用码头之前。我在使用默认项目时遇到了这个问题。一步一步我在做什么: git clone github.com/spring-guides/gs-spring-boot.git 在 gs-spring-boot/complete, mvn package & java -jar target/gs-spring-boot-0.1.0.jar 就是这样。 @ satya 我想了很多(关于资源),但没有关于我可能需要什么样的资源的其他信息。我还查看了 ResourceUtils.java,但这并没有帮助阐明这一点。
  • @AndyWilkinson 我已经确认这是一个环境问题。我可以在 linux VM 中很好地启动应用程序,但无论出于何种原因,我在我的 Mac 上遇到了这个问题。

标签: spring spring-boot


【解决方案1】:

添加: server.ssl.enabled=false 在我的 application.properties 中解决了这个问题。我假设基于父引导启动器 pom 的 ssl 配置是预期的?同样,不确定为什么这在 linux VM 中运行良好。 没有时间深入研究这个,也许其他人可以阐明更多。

【讨论】:

  • 我猜你的 Mac 有一个环境变量或类似的尝试配置 SSL
【解决方案2】:

我一直在禁用和启用 HTTPS (server.ssl.enabled=true) 但忘记添加这些:

server.ssl.key-store=file:///Users/...
server.ssl.key-store-password=******

将来可能会对某人有所帮助。

【讨论】:

    【解决方案3】:

    这可能对某人有帮助:

    任何 ssl 配置都可能导致这种情况,在我的情况下,我有以下剩余配置:

    server.ssl.protocol=TLS
    server.ssl.enabled-protocols=TLSv1.2
    

    删除这些解决了问题。

    【讨论】:

      【解决方案4】:

      当我有 ssl.enabled : true 但未设置其他 SSL 参数时发生了这种情况(因为 YAML 文件中的缩进错误)。这就是它在 config/application.yaml 中运行良好时的样子。

      environments:
        production:
          server:
            port: 9080
            ssl:
              enabled: true
              key-store: /home/peter/app/ucast.rewara.com/ucast.rewara.com.cert.jks
              key-store-password: drowssapekaf
              key-password: ewerw23121sdsd
              key-alias: ucast.rewara.com
          grails:
            serverURL: "https://ucast.rewara.com:9080"`
      

      【讨论】:

        【解决方案5】:

        我认为您可以在文件 application.properties 中进行配置

        #SSL:
        server.ssl.enabled=false
        

        如果你想在本地构建。它不会强制您为 SSL (http://) 提供相关的证书
        否则,您在远程服务器 (https://) 中构建 -> 使用 ssl -> true。

        【讨论】:

          猜你喜欢
          • 2015-05-10
          • 2020-08-04
          • 1970-01-01
          • 1970-01-01
          • 2018-08-17
          • 1970-01-01
          • 2022-09-28
          相关资源
          最近更新 更多