Spring Cloud Config 和静态内容

Ahm*_*ila 3 java spring-mvc spring-boot spring-cloud

我有一个使用 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"}
Run Code Online (Sandbox Code Playgroud)

当我禁用@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";
      }
    }
Run Code Online (Sandbox Code Playgroud)

spe*_*ibb 5

默认情况下,配置服务器具有匹配的 api /*/*。您可以通过更改spring.cloud.config.server.prefix=myroot.