Spring WebMVC support?
See original GitHub issueHi, Did you try to integrate with SpringMVC? I tried to use minimal spring-webmvc project. But it can’t compile templates.
Here is my minimal MVC setup.
public class Message{
private final String text;
public Message(String text) {
this.text = text;
}
public String getText() {
return text;
}
}
@ComponentScan("net.hurelhuyag.jtetest")
@EnableWebMvc
@Controller
class Config implements WebMvcConfigurer {
@Bean
TemplateEngine templateEngine(ServletContext context) throws MalformedURLException, URISyntaxException {
var root = context.getResource("/WEB-INF/views/").toURI();
var codeResolver = new DirectoryCodeResolver(Path.of(root));
return TemplateEngine.create(codeResolver, ContentType.Html);
}
@Bean
ViewResolver viewResolver(TemplateEngine templateEngine){
return (viewName, locale) -> (model, request, response) -> {
templateEngine.render(viewName+".jte", (Map<String, Object>) model, new PrintWriterOutput(response.getWriter()));
};
}
@GetMapping({"/"})
String index(ModelMap model){
model.put("message", new Message("Hello World"));
return "index";
}
}
Error:
/tmp/demo-jte-classes/gg/jte/generated/JteindexGenerated.java:2: error: package net.hurelhuyag.jtetest does not exist
import net.hurelhuyag.jtetest.Message;
^
/tmp/demo-jte-classes/gg/jte/generated/JteindexGenerated.java:6: error: package gg.jte.html does not exist
public static void render(gg.jte.html.HtmlTemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor, Message message) {
^
/tmp/demo-jte-classes/gg/jte/generated/JteindexGenerated.java:6: error: package gg.jte.html does not exist
public static void render(gg.jte.html.HtmlTemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor, Message message) {
^
/tmp/demo-jte-classes/gg/jte/generated/JteindexGenerated.java:6: error: cannot find symbol
public static void render(gg.jte.html.HtmlTemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor, Message message) {
^
symbol: class Message
location: class JteindexGenerated
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
17. Web MVC framework - Spring
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler ...
Read more >spring-webmvc 6.0.2 javadoc (org.springframework)
Locale support classes for Spring's web MVC framework. org.springframework.web.servlet.mvc. Standard controller implementations for the Servlet MVC ...
Read more >org.springframework » spring-webmvc - Maven Repository
Spring webmvc contains Spring's model-view-controller (MVC) and REST Web Services implementation for web applications. It provides a clean separation ...
Read more >How Spring MVC Really Works - Stackify
This is an in-depth look at the powerful features and internal workings of Spring Web MVC, which is a part of the Spring...
Read more >Introduction to Spring Web MVC - Apache NetBeans
The IDE provides built-in support for Spring Framework 4.x and 3.x. Framework libraries are packaged with the IDE and are automatically added to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@hurelhuyag I found the working configuration for your project. Here is the fork with the working version: https://github.com/izogfif/demo-spring-jte @casid maybe add this as a demo for spring-webmvc?
In
src/main/java/net/hurelhuyag/jtetest/Config.java
file I replacedwith
in
pom.xml
I changedto
Hey @izogfif, thanks for sharing! I added a link to your repostitory to the jte readme.