【问题标题】:Spring don't displaying webpage and can't found resourceSpring不显示网页并且找不到资源
【发布时间】:2021-09-24 04:59:49
【问题描述】:

我使用Spring 框架和Thymeleaf 编写了简单的Java 应用程序。在我的 IDE 上,它工作得很好,但是当我制作 JAR 工件并将其导出到我的 linux 服务器时,它正在启动,但我收到了这个错误:

02:56:06.447 [main] INFO com.ibcs.rfid.RfidApplication - Started RfidApplication in 142.158 seconds (JVM running for 151.664)
Jul 15, 2021 2:56:10 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring DispatcherServlet 'dispatcherServlet'
02:56:10.948 [http-nio-8080-exec-1] INFO org.springframework.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
02:56:10.954 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Detected StandardServletMultipartResolver
02:56:10.959 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Detected AcceptHeaderLocaleResolver
02:56:10.964 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Detected FixedThemeResolver
02:56:11.171 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@1db0c88
02:56:11.251 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Detected org.springframework.web.servlet.support.SessionFlashMapManager@1384aac
02:56:11.257 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
02:56:11.261 [http-nio-8080-exec-1] INFO org.springframework.web.servlet.DispatcherServlet - Completed initialization in 308 ms
02:56:11.638 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - GET "/", parameters={}
02:56:11.745 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to com.ibcs.rfid.controllers.ServiceControllers#loginForm(Model)
02:56:12.994 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.view.ContentNegotiatingViewResolver - Selected 'text/html' given [text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8]
02:56:13.003 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.view.InternalResourceView - View name 'login', model {authentication=com.ibcs.rfid.models.Authentication@14147d2, org.springframework.validation.BindingResult.authentication=org.springframework.validation.BeanPropertyBindingResult: 0 errors}
02:56:13.065 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.view.InternalResourceView - Forwarding to [login]
02:56:13.265 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - "FORWARD" dispatch for GET "/login", parameters={}
02:56:13.383 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped to ResourceHttpRequestHandler [Classpath [META-INF/resources/], Classpath [resources/], Classpath [static/], Classpath [public/], ServletContext [/]]
02:56:13.434 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Resource not found
02:56:13.441 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Exiting from "FORWARD" dispatch, status 404
02:56:13.461 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Completed 404 NOT_FOUND
02:56:13.480 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - "ERROR" dispatch for GET "/error", parameters={}
02:56:13.549 [http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)

我的文件树:

├───.idea
│   ├───artifacts
│   └───libraries
├───.mvn
│   └───wrapper
├───out
│   └───artifacts
│       └───rfid_jar
├───src
│   ├───main
│   │   ├───java
│   │   │   ├───com
│   │   │   │   └───ibcs
│   │   │   │       └───rfid
│   │   │   │           ├───controllers
│   │   │   │           ├───models
│   │   │   │           └───storers
│   │   │   └───META-INF
│   │   └───resources
│   │       ├───jsons
│   │       ├───static
│   │       │   ├───css
│   │       │   ├───img
│   │       │   └───js
│   │       └───templates
│   └───test
│       └───java
│           └───com
│               └───ibcs
│                   └───rfid
└───target
    ├───classes
    │   ├───com
    │   │   └───ibcs
    │   │       └───rfid
    │   │           ├───controllers
    │   │           ├───models
    │   │           └───storers
    │   ├───jsons
    │   ├───static
    │   │   ├───css
    │   │   ├───img
    │   │   └───js
    │   └───templates
    ├───generated-sources
    │   └───annotations
    ├───generated-test-sources
    │   └───test-annotations
    └───test-classes
        └───com
            └───ibcs
                └───rfid

还有我的application.properties 内容:

spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

这里也是我Controller的一部分:

    @GetMapping("/")
    public String loginForm(Model model)
    {
        model.addAttribute("authentication", new Authentication());
        return "login";
    }

有什么想法可以解决吗? 此外,我仅限于 .jar 文件,因为它必须在 Zebra FX9600 上运行

【问题讨论】:

  • 你是如何生成 jar 文件的?
  • 使用INTELIJ IDEA:文件|项目结构 | Artifacts 我有我的 rfid.jar 文件,然后我就去 Build |神器 | rfid.jar
  • 不要。您正在使用 Spring Boot,因此请使用 Maven 或 Gradle(无论您使用什么来管理您的依赖项)。否则您将无法获得所需的一切。

标签: java spring spring-boot spring-mvc thymeleaf


【解决方案1】:

解决方案(来自 cmets):

  • 用 maven 构建它

谢谢M。 Deinum

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2020-01-03
    • 2015-07-13
    相关资源
    最近更新 更多