1

Is there any restriction on using thymeleaf with springboot application with main class annotated with @EnableWebFlux.

If I just comment @EnableWebFlux in the below class everything works. Wasted 2 days just to find where to comment to get things working :).

@EnableWebFlux
@SpringBootApplication(exclude = {GsonAutoConfiguration.class})
public class BootApplication {

    public static void main(String[] args)
    {
        SpringApplication springApplication = new SpringApplication(BootApplication.class);
        springApplication.setWebApplicationType(WebApplicationType.REACTIVE);
        springApplication.run(args);
    }
}

Uncommenting it I cannot reach any of my html pages and error shown is below:

Whitelabel Error Page This application has no configured error view, so you are seeing this as a fallback.

Thu Apr 11 20:20:13 IST 2019 There was an unexpected error (type=Internal Server Error, status=500). Could not resolve view with name 'index'.

Below is my controller class:

@Controller
public class SimpleController {
    @Value("${spring.application.name}")
    String appName;

    @GetMapping(path="/home", produces = "text/html")
    public String homePage(Model model) {
        //model.addAttribute("appName", appName);
        return "home";
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(final Model model) {

        // data streaming, data driven mode.
        IReactiveDataDriverContextVariable reactiveDataDrivenMode =
                new ReactiveDataDriverContextVariable(Flux.just("a") , 1);

        model.addAttribute("movies", reactiveDataDrivenMode);

        return "index";

    }
}

application.properties :

server.port=8099
spring.thymeleaf.cache=false
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

spring.application.name=Bootstrap Spring Boot

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.nano</groupId>
    <artifactId>thymeleaf</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>thymeleaf</name>
    <url>http://maven.apache.org</url>

    <properties>
        <log4jVersion.version>2.10.0</log4jVersion.version>
        <slf4jVersion.version>1.7.25</slf4jVersion.version>
        <springBoot.version>2.1.3.RELEASE</springBoot.version>
        <jackson.version>2.9.8</jackson.version>
        <buildGroup>d</buildGroup>
        <buildName>e</buildName>
        <deployable>true</deployable>

    </properties>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>http://repo.spring.io/libs-snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>file</id>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <url>file://${project.basedir}/lib</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${springBoot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <version>${springBoot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>${springBoot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>${springBoot.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4jVersion.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>${slf4jVersion.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4jVersion.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4jVersion.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>${log4jVersion.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <!--<version>3.1</version> -->
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <skipSource>false</skipSource>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
    </build>
</project>
nanosoft
  • 2,913
  • 4
  • 41
  • 61
  • Could you add your POM too? – Darren Forsythe Apr 11 '19 at 15:21
  • According to this https://stackoverflow.com/questions/51843344/what-is-the-function-of-the-enablewebflux-annotation that annotation `@EnableWebFlux` simply disables all the auto configuration (which is probably why Thymeleaf stops working). What are you trying to accomplish? – Metroids Apr 11 '19 at 20:22
  • @Metroids - I just want to make a spring boot service which will support response in different formats like json, xml including html. To support html, I am using thymeleaf. Also wanted to use reactive implementation so used webflux. – nanosoft Apr 12 '19 at 10:37

0 Answers0