Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf templates and static resources in the same directory

Is it possible to configure Thymeleaf/Spring application to serve templates and static resources from the same directory (either via configuration or custom view resolver)?

I'm using Thymeleaf just for localization of the templates and rest of the page logic is handled by Angular JS. I have it working with templates and static content separated but this will be a big project and I want to use recommended structure where all files related to one page are located in the same "package".

I'm looking for structure that looks like this:

└── src
    └── main
        └── java
            └── HelloController.java
            └── LoginController.java
        └──resources
            └──templates
               └──hello
                  └──hello.html (dynamic thymeleaf template)
                  └──hello.js (static resource)
                  └──hello.css (static resource)
               └──login
                  └──login.html
                  └──login.js
                  └──login.css
        └──webapp
            └──WEB-INF
               └──web.xml

Thank you for any suggestions.

like image 741
xMort Avatar asked Nov 11 '22 00:11

xMort


1 Answers

This is feasible, however the risk you have is that you will also expose the html template itself as a static resource which is not a good idea. Can I instead recommend having a parallel hierarchy for static resources along these lines:

src 
   main
       resources
            static
                 js
                    hello
                        hello.js
                    login 
                        login.js
                 css
                   hello
                        hello.css
                   login
                        login.css
            templates
                   hello
                        hello.html
                   login
                       login.html
like image 52
Biju Kunjummen Avatar answered Nov 15 '22 11:11

Biju Kunjummen