小编Ton*_* Tc的帖子

@EnableWebFlux 注解的作用是什么

我有一个非常简单的带有 freemarker 的 webflux 演示应用程序,它有以下文件:

1.WebFluxDemoApplication.java

@SpringBootApplication
public class WebFluxDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebFluxDemoApplication.class, args);
    }

    @Controller
    class HomeController {
        @GetMapping("/hello")
        public String hello() {
            return "index";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

2.index.ftl(位于classpath:/templates下)

<html>
    <head>
        <title>demo</title>
    </head>
    <body></body>
</html>
Run Code Online (Sandbox Code Playgroud)

3.application.yml(无需任何配置)

4.pom.xml(带spring-boot-starter-freemarkerspring-boot-starter-webflux

我可以通过http://localhost:8080/hello使用这些文件获得正常页面,但是如果我添加@EnableWebFluxWebFluxDemoApplication,则会显示错误java.lang.IllegalStateException: Could not resolve view with name 'index'.

我注意到Spring WebFlux 的官方指南指出@EnableWebFlux用于配置 freemarker。实际上它适用于模板文件,但静态资源似乎有问题。

例如,我在 下放了一个main.js文件,然后在 中classpath:/templates/js/添加,然后我得到一个错误说 …

spring freemarker spring-boot spring-webflux

6
推荐指数
1
解决办法
5986
查看次数

Spring云领事中的配置值未自动更改

我有一个非常简单的Spring云应用程序如下:

@SpringBootApplication
@EnableDiscoveryClient
@RestController
@EnableAutoConfiguration
public class SpringCloudConsulDemoApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(SpringCloudConsulDemoApplication.class).web(true).run(args);
    }

    @Value("${my.message}")
    private String message; 

    @RequestMapping("/")
    public String home() {
        return message;
    }

    @RequestMapping("/health")
    public String health() {
        return "Hello world";
    }
}
Run Code Online (Sandbox Code Playgroud)

我在/ config/SpringCloudConsulDemo,dev /下的consul中配置了"my.message".当我更改"my.message"的值时,我在spring cloud app中获得了一些输出:

2016-06-26 12:41:18.621  INFO 1187 --- [pool-1-thread-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@601c9895: startup date [Sun Jun 26 12:41:18 CST 2016]; root of context hierarchy
2016-06-26 12:41:18.631  INFO 1187 --- [pool-1-thread-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and …
Run Code Online (Sandbox Code Playgroud)

consul spring-cloud

1
推荐指数
1
解决办法
1003
查看次数