Skip to content

Error resolving template with java -jar #7246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LeonFelipeCordero opened this issue Oct 28, 2016 · 2 comments
Closed

Error resolving template with java -jar #7246

LeonFelipeCordero opened this issue Oct 28, 2016 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@LeonFelipeCordero
Copy link

Hi!!!
I'm having problem trying to run a spring-boot app inside my production environment with java -jar target/myjar.jar, before launch the app to production I was running it in my localhost with the maven plugin and it was working perfect, here is an example of one controller:

    @RequestMapping(value = "/")
    public ModelAndView home(ModelAndView modelAndView) {
        Crawl crawl = crawlService.getLastNormalCrawl();

        if(crawl != null){
            setCrawlInfo(modelAndView, crawl);
            modelAndView.setViewName("/layout/home");
            return modelAndView;
        } else{
            modelAndView.setViewName("/index");
            return modelAndView;
        }
    }

as You can see I'm Returning a ModelAndView, the view is added and the objects to the model too.

As I said if this code ran with the maven plugin it works, but with java -jar I get this message:
Error resolving template "/layout/home".

The solution that I take was chenge the return object to String:

@RequestMapping(value = "/")
    public String home(Model model) {
        Crawl crawl = crawlService.getLastNormalCrawl();

        if(crawl != null){
            setCrawlInfo(model, crawl);
            return "layout/home";
        } else{
            return "index";
        }
    }

This works for maven plugin and and java -jar.

Here is my spring-boot version:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

I did not found a this exactly problem, so I don't know if is a bug, is something wrong with my code or something else.

I hope this could help in something, If you have and answer I want to know it.

Thank you very much!!!!!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 28, 2016
@wilkinsona
Copy link
Member

Your view names are different in the two examples: /layout/home vs layout/home. You want the latter.

@wilkinsona
Copy link
Member

Duplicates #3559.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants