YourGreatDream
YourGreatDream

Reputation: 51

Thymeleaf. Server does not see templates directory, how can I point to it if I packaged app to jar

I have a java Spring Boot application that uses Thymeleaf and Model in my Controller. Also I have templates directory in my resources where all .html pages are located. My Controller

@Controller
@RequestMapping("/frontView")
public class FrontController {
    private final CameraService cameraService;

    public FrontController(CameraService cameraService) {
        this.cameraService = cameraService;
    }

    @RequestMapping(value = "/firstCameraData", method = RequestMethod.GET)
    public String dataListFromFirstCamera(Model model) {
        cameraService.returnAllCars(model, "firstCamera");
        return "firstCamera.html";
    }

Part of .pom file that I think is the only useful for determining the issue

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <excludes>
                    <exclude>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                    </exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>de.qaware.maven</groupId>
            <artifactId>go-offline-maven-plugin</artifactId>
            <version>1.2.8</version>
            <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadoc>false</downloadJavadoc>
            </configuration>
        </plugin>
    </plugins>
</build>

I don't have any configuration classes for my application or thymeleaf - the problem I stuck with - locally everything works just fine. My application is running locally on Tomcat and I can see localhost:8080/frontView/firstCameraData page just fine, but after deploying my application on server in .jar file I'm getting 404 page not found

I think that the problem is - when my application is running on server it does not see resources/templates directory. I know that it maybe could be solved by repackaging the application in .war and putting my .html files in webapp directory, but I don't want this. Are there any solutions that will allow me to let the server see that directory being in .jar format?

Upvotes: 1

Views: 243

Answers (1)

YourGreatDream
YourGreatDream

Reputation: 51

Actually that wasn't the problem of packaging in .jar or .war. I had the helm configured, and in my values.yaml I had the default path...

corePath: /core

So, for my controller to work it should be done like this

@Controller
@RequestMapping("/core/frontView")
public class FrontController {
    private final CameraService cameraService;

    public FrontController(CameraService cameraService) {
        this.cameraService = cameraService;
    }

    @RequestMapping(value = "/firstCameraData", method = RequestMethod.GET)
    public String dataListFromFirstCamera(Model model) {
        cameraService.returnAllCars(model, "firstCamera");
        return "firstCamera.html";
    }

And after that the correct link would be http://*****/core/frontView/firstCameraData

Many thanks to @chrylis -cautiouslyoptimistic for help

Upvotes: 1

Related Questions