在部署为WAR

时间:2017-11-21 21:53:26

标签: spring spring-webflux

在tomcat中将Spring WebFlux应用程序部署为war文件时面对异常,使用AbstractAnnotationConfigDispatcherHandlerInitializer扩展并实现getConfigClasses方法,如下所示。

应用

@SpringBootApplication
public class TestSpringApplication extends AbstractAnnotationConfigDispatcherHandlerInitializer {

    public static void main(String[] args) {
        SpringApplication.run(TestSpringApplication.class, args);
    }
    @Override
    protected Class<?>[] getConfigClasses() {
        return new Class[]{
            WebConfig.class
        };
    }

控制器

@Controller
public class TestSpringController {

    @RequestMapping("/test")
    public Mono<String> hello(Model model){

         return Mono.just("account");
    }
}

注意:account.html位于resources / templates

异常

java.lang.IllegalStateException: Could not resolve view with name 'account'.
    at org.springframework.web.reactive.result.view.ViewResolutionResultHandler.lambda$resolveViews$3(ViewResolutionResultHandler.java:276) ~[spring-webflux-5.0.1.RELEASE.jar:5.0.1.RELEASE]
    at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:107) [reactor-core-3.1.1.RELEASE.jar:3.1.1.RELEASE]

2 个答案:

答案 0 :(得分:1)

Spring Boot目前不支持部署为WAR的WebFlux应用程序。

您在这里混合了Spring Framework推荐的设置(请参阅the reference documentation,特别是指向AbstractServletHttpHandlerAdapterInitializer的注释) - 以及Spring Boot MVC应用程序的WAR设置。

如果您想运行Spring Boot WebFlux应用程序,请考虑可执行的JAR部署模型。

答案 1 :(得分:0)

使用@RestController代替TestSpringController类的@Controller注释