question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring WebMVC support?

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
izogfifcommented, Jun 25, 2021

@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 replaced

return TemplateEngine.create(codeResolver, Path.of("/tmp/demo-jte-classes"), ContentType.Html);

with

return TemplateEngine.create(codeResolver, Path.of("/WEB-INF/classes/"), ContentType.Html, this.getClass().getClassLoader());

in pom.xml I changed

<jte.version>1.5.0</jte.version>

to

<jte.version>1.11.0</jte.version>
0reactions
casidcommented, Jun 25, 2021

Hey @izogfif, thanks for sharing! I added a link to your repostitory to the jte readme.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found