spring boot 不启动静态网页内容 [英] spring boot not launching static web content

查看:45
本文介绍了spring boot 不启动静态网页内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Spring Boot 应用程序中启动 index.html,但看到 404.我缺少什么依赖项?

build.gradle(多项目)

project('子项目'){应用插件:'spring-boot'编译("org.springframework.boot:spring-boot-starter-web:1.0.0.RC5",org.springframework.boot:spring-boot-starter-actuator:1.0.0.RC5".. 一些特定于应用程序的依赖项)

项目结构:

<前>主项目-- 子项目源文件主要的资源索引.html

应用类:

@Configuration@EnableAutoConfiguration类应用{公共静态无效主(字符串 [] args){SpringApplication.run([SpringServlet, Application, "classpath:/META-INF/com/my/package/bootstrap.xml"] as Object[], args)}}**启动 http://localhost:8080/index.html 会抛出 404.**

解决方案

找到根本原因.将 SpringServlet 的 Url 映射更改为Rest"资源特定路径修复了它.之前的 "/*" 也被 SpringServlet 解释,无法渲染 index.html.

class 应用程序扩展 SpringBootServletInitializer {公共静态无效主(字符串 [] args){SpringApplication.run([Application, "classpath:/META-INF/com/my/package/mgmt/bootstrap.xml"] as Object[], args)}受保护的 SpringApplicationBuilder 配置(SpringApplicationBuilder 应用程序){返回 application.sources(Application);}@豆ServletRegistrationBean jerseyServlet() {ServletRegistrationBean 注册 = new ServletRegistrationBean(new SpringServlet(), "/rest/*");映射<字符串,字符串>参数 = ["com.sun.jersey.config.property.packages": "com.my.package.mgmt.impl;com.wordnik.swagger.jersey.listing"]注册.setInitParameters(params)退货登记;}@豆ServletRegistrationBean jerseyJaxrsConfig() {ServletRegistrationBean 注册 = new ServletRegistrationBean(new DefaultJaxrsConfig(), "/api/*");映射<字符串,字符串>params = ["swagger.api.basepath": "http://localhost:8080/api", "api.version": "0.1.0"]注册.setInitParameters(params)退货登记;}

Am trying to launch index.html in my spring boot app but see 404. What dependency am I missing?

build.gradle (multi project)

project('sub-project')
{
apply plugin: 'spring-boot'
compile (
    "org.springframework.boot:spring-boot-starter-web:1.0.0.RC5",
    "org.springframework.boot:spring-boot-starter-actuator:1.0.0.RC5"
.. few more app specific dependencies
)

project structure:

MainProject
  -- sub-project
     src
       main
          resources
             index.html

Application class:

@Configuration
@EnableAutoConfiguration
class Application {
    public static void main(String[] args) {
        SpringApplication.run([SpringServlet, Application, "classpath:/META-INF/com/my/package/bootstrap.xml"] as Object[], args)
    }
}

**Launching http://localhost:8080/index.html throws 404.**

解决方案

Found the root cause. Changing the SpringServlet's Url mappings to "Rest" resources specific path fixed it. Earlier "/*" was also interpreted by SpringServlet and was not able to render the index.html.

class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run([Application, "classpath:/META-INF/com/my/package/mgmt/bootstrap.xml"] as Object[], args)
    }

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application);
    }

    @Bean
    ServletRegistrationBean jerseyServlet() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new SpringServlet(), "/rest/*");
        Map<String, String> params = ["com.sun.jersey.config.property.packages": "com.my.package.mgmt.impl;com.wordnik.swagger.jersey.listing"]
        registration.setInitParameters(params)
        return registration;
    }

    @Bean
    ServletRegistrationBean jerseyJaxrsConfig() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new DefaultJaxrsConfig(), "/api/*");
        Map<String, String> params = ["swagger.api.basepath": "http://localhost:8080/api", "api.version": "0.1.0"]
        registration.setInitParameters(params)
        return registration;
    }

这篇关于spring boot 不启动静态网页内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆