Spring and thymelear with html as resources

I am learning Java related technologies (and I am relatively new) and am trying to write a simple web application with Spring and Thymeleaf as frontend and I have some modularity issues.

I found that it is used to package the .html filesinto of the WEB-INF directory for security purposes, but as far as I am guessing this means I have to put all my views, have controllers in these projects. I want to avoid this by having many projects, for example:

  • Web application
  • admin module
  • custom module
  • core-module

and they each have their own modular controllers and views (htmls) and the web application bundles them into a single, large project.

In Thymelaf I found something like ClassLoaderTemplateResolver and got (maybe a dumb idea) how to split a large project into many of them - put htmls in the classpath resource directory. Thanks to this, I can request any kind of html from any module project. Does this violate some security considerations?

I would like to ask if anyone has a similar problem and found the right solution, how to elegantly split the html web application project into many smaller "context sensitive" projects?

Here is my current project structure. The blue arrow indicates which view is connected to the controller: http://prntscr.com/4tqt9m

This is my first question asked here, so I hope you will treat me with some understanding.

Thanks in advance.


source to share

1 answer

You might be able to combine multiple Spring and Thymeleaf modules at runtime using classpath search. Just make sure you give a different qualified name / folder structure (ex: two files named views / index.html on different packages can cause confusing inconsistencies)

With Spring, if you've configured trajectory scanning correctly, it should consider jar packages in the classpath.

With Thymeleaf try to adjust TemplateResolver prefixed example classpath:/templates/

, and then on different modules create a folder structure, e.g. src/main/resources/templates/package-a/foo.html

, src/main/resources/templates/package-b/foo.html

. I haven't tried this yet, and I'm not 100% sure if the classloader can combine everything ok.



All Articles