【问题标题】:Spring Cloud Config and static contentSpring Cloud Config 和静态内容
【发布时间】:2015-10-19 15:10:40
【问题描述】:

我有一个使用 Spring 云配置 (--spring.profiles.active=native) 的应用程序,并且还在同一个应用程序中提供了一些 html 页面。在我引入静态资源(src/main/resources/css/bootstrap-switch.css)之前,一切都很好。对 http://localhost:8080/css/bootstrap-switch.css 的 URL 调用失败并出现此异常:

{"timestamp":1438114326940,"status":406,"error":"Not Acceptable","exception":"org.springframework.web.HttpMediaTypeNotAcceptableException","message":"Could not find acceptable representation","path":"/css/bootstrap-switch.css"}

当我禁用@EnableConfigServer 时,URL 会返回 CSS 内容。我使用的是 Spring Cloud Config 1.0.2 版。

这是我可以重现此问题的极简代码:

    @SpringBootApplication
    @EnableConfigServer
    public class Application {
    public static void main(String args[]) {
      SpringApplication.run(ApplicationConfiguration.class, args);
    }
    }


    @Configuration
    @SpringBootApplication
    class ApplicationConfiguration {
      @Bean
      public TestController testController() {
        return new TestController();
      }
      @Bean
      public MvcController mvcController() {
        return new MvcController();
      }
    }


    @RestController
    class TestController {
      @RequestMapping("/test")
      @ResponseBody
      public String test() {
        return "hello world";
      }
    }

    @Controller
    class MvcController {
      @RequestMapping("/landing")
      public String landingPage() {
        return "landing";
      }
    }

【问题讨论】:

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


    【解决方案1】:

    配置服务器默认有一个匹配/*/*的api。您可以通过更改spring.cloud.config.server.prefix=myroot来移动api的根。

    【讨论】:

      猜你喜欢
      • 2016-08-12
      • 2018-06-26
      • 2016-09-29
      • 2016-02-18
      • 2018-02-10
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多