Thymeleaf templates error in Heroku

Asked

Viewed 920 times

1

I implemented my application on Heroku, just for testing... Locally everything works well, but in Heroku after I log in with the credentials I am directed to the page sac/index, what is right, but return to me:

"Whitelabel Error Page

This application has no Explicit Mapping for /error, so you are Seeing this as a fallback.

Tue May 30 19:56:32 UTC 2017 There was an Unexpected error (type=Internal Server Error, status=500). Error resolving template "/Sac/index", template Might not exist or Might not be accessible by any of the configured Template Resolvers"

However, when I access another page as /sac/listUsers works normally.

This is my Controller:

@RequestMapping("/sac/index")
public ModelAndView home(){
    ModelAndView modelAndView = new ModelAndView();
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    User user = userService.findUserByEmail(auth.getName());
    modelAndView.addObject("userName", user.getName() + " (" + user.getEmail() + ")");
    modelAndView.setViewName("/sac/index");
    return modelAndView;
}

My http configuration:

@Override
protected void configure(HttpSecurity http) throws Exception {      
    http.
        authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers("/login").permitAll()              
            .antMatchers("/sac/registration").hasAuthority("ADMIN")
            .antMatchers("/sac/consultarUsuarios").hasAuthority("ADMIN")
            .antMatchers("/sac/index").hasAnyAuthority("ADMIN", "SUPPORT")
            .antMatchers("/sac/**").hasAnyAuthority("ADMIN", "SUPPORT").anyRequest()                
            .authenticated().and().csrf().disable().formLogin()
            .loginPage("/login").failureUrl("/login?error=true")
            .defaultSuccessUrl("/sac/index")
            .usernameParameter("email")
            .passwordParameter("password")
            .and().logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/login").and().exceptionHandling()
            .accessDeniedPage("/access-denied");
}

Pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>

            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <finalName>${project.artifactId}</finalName>
                    </configuration>
                </execution>
            </executions>
        </plugin>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <finalName>${project.artifactId}</finalName>
            </configuration>
        </plugin>
    </plugins>

</build>

Application properties:

# ===============================
# = Thymeleaf configurations
# ===============================
spring.thymeleaf.enabled=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

Someone knows what I’m doing wrong?

  • Welcome to Stack Overflow in Portuguese. In case you Haven’t noticed, this is the SO Portuguese community, if you’re Looking to get help in English Please visit the SO English Community. If you’re Looking to get help in English, Please Edit and Translate your Question.

  • @ramaral I’m Sorry, I didn’t saw that T_T

1 answer

2


Yesterday a user who unfortunately do not remember the nick answered and gave me the solution. Unfortunately the same deleted the comment. So stay here my thanks!

The solution given by this user was to remove the first "/" from the following line in my controller:

Before:

modelAndView.setViewName("/sac/index");

Afterward:

modelAndView.setViewName("sac/index");
  • It was me, I had the same problem, but I wasn’t sure if it was, so I removed the comment

  • 1

    @Denisrudneidesouza was exactly what you had talked about, saved my life man!!! Thank you! hahahaha

Browser other questions tagged

You are not signed in. Login or sign up in order to post.