Olá estou com esse erro no spring, dizendo que não esta encontrando o tamplate, porem o tamplate está acessivel. help me!!
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon May 24 20:11:46 BRT 2021
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/login.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/login.html]")
Minha Classe UserController:
package com.hobbyour.hobbyour.controller;
import java.security.NoSuchAlgorithmException;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import com.hobbyour.hobbyour.Exceptions.ServiceExceptions;
import com.hobbyour.hobbyour.entity.UserEntity;
import com.hobbyour.hobbyour.service.UserService;
import com.hobbyour.hobbyour.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/index")
public ModelAndView index() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index");
return mv;
}
@GetMapping("/register")
public ModelAndView register(){
ModelAndView mv = new ModelAndView();
mv.addObject("UserEntity", new UserEntity());
mv.setViewName("register");
return mv;
}
@PostMapping("saveUser")
public ModelAndView register(UserEntity userEntity) throws Exception{
ModelAndView mv = new ModelAndView();
userService.seveUser(userEntity);
mv.setViewName("redirect:/");
return mv;
}
@GetMapping("/")
public ModelAndView login(){
ModelAndView mv = new ModelAndView();
mv.setViewName("login");
mv.addObject("UserEntity", new UserEntity());
return mv;
}
@PostMapping("/logar")
public ModelAndView login(@Valid UserEntity user, BindingResult br, HttpSession session) throws NoSuchAlgorithmException, ServiceExceptions{
ModelAndView mv = new ModelAndView();
mv.addObject("user", new UserEntity());
if (br.hasErrors()) {
mv.setViewName("register");
}
UserEntity userEntity = userService.logar(user.getEmail(), Util.md5(user.getPasswd()));
if (userEntity == null) {
mv.addObject("msg", "Usuario não Cadastrado!");
}else{
session.setAttribute("usuarioLogado", userEntity);
return index();
}
return mv;
}
}
Minha classe UserRepository:
package com.hobbyour.hobbyour.repository;
import com.hobbyour.hobbyour.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface UserRepository extends JpaRepository<UserEntity, Long>{
@Query("select e from UserEntity e where e.email = :email")
public UserEntity findByEmail(String email);
@Query("select j from UserEntity j where j.email = :email and j.passwd = :passwd")
public UserEntity logar(String email, String passwd);
}
Minha classe UserService:
package com.hobbyour.hobbyour.service;
import java.security.NoSuchAlgorithmException;
import com.hobbyour.hobbyour.Exceptions.CriptoExistsException;
import com.hobbyour.hobbyour.Exceptions.EmailExistsException;
import com.hobbyour.hobbyour.Exceptions.ServiceExceptions;
import com.hobbyour.hobbyour.entity.UserEntity;
import com.hobbyour.hobbyour.util.Util;
import com.hobbyour.hobbyour.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
public void seveUser(UserEntity userEntity) throws Exception{
try {
if (userRepository.findByEmail(userEntity.getEmail()) != null) {
throw new EmailExistsException("Já existe um email cadastrado para: "+ userEntity.getEmail());
}
userEntity.setPasswd(Util.md5(userEntity.getPasswd()));
userEntity.setBirthdate(Util.getDateTime());
} catch (NoSuchAlgorithmException e) {
throw new CriptoExistsException("Erro na criptografia da senha");
}
userRepository.save(userEntity);
}
public UserEntity logar(String email, String passwd) throws ServiceExceptions{
UserEntity login = userRepository.logar(email, passwd);
return login;
}
}
Minha classe de percistencia:
package com.hobbyour.hobbyour.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import org.springframework.format.annotation.DateTimeFormat;
@Entity
@Table(name = "tbuser", schema = "hobbyour")
public class UserEntity implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@NotNull
private Long id;
@Column(name = "username")
@NotNull
private String userName;
@Column(name = "fname")
@NotNull
private String firstName;
@Column(name = "surname")
@NotNull
private String surName;
@Column(name = "email")
@Email
@NotNull
private String email;
@Column(name = "passwd")
@NotNull
private String passwd;
@Column(name = "birthdate")
@DateTimeFormat(pattern = "dd/MM/yyyy")
@NotNull
private String birthdate;
@Column(name = "gender")
@NotNull
private String gender;
@Column(name = "region")
@NotNull
private String region;
public UserEntity() {
super();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getSurName() {
return surName;
}
public void setSurName(String surName) {
this.surName = surName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getBirthdate() {
return birthdate;
}
public void setBirthdate(String date) {
this.birthdate = date;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getRegion() {
return region;
}
public void setRegion(String region){
this.region = region;
}
}
Meu Template HTML login:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0"
crossorigin="anonymous">
<link rel="stylesheet" href="/css/style.css">
<title>Inscreva-se</title>
</head>
<header>
<div class="logo">
<h1>hobbyour</h1>
</div>
</header>
<body>
<section>
<div class="container">
<form method="POST" th:object="${user}" action="/logar" >
<div class="step step-1 index active">
<h1>Login</h1>
<h5>Divirta-se com seu hobby!</h5>
<div class="form-group">
<!-- <label for="firstname">Primeiro Nome</label> -->
<input type="email" placeholder="Email" th:field="*{email}">
</div>
<div class="form-group">
<!-- <label for="surname">SobreNome</label> -->
<input type="password" placeholder="Senha" th:field="*{passwd}">
</div>
<button type="submit" class="submit-btn" th:href="@{/logar}">Entrar</button>
<div class="_8icz"></div>
<a class="" th:href="@{register}">Não possui cadastro?</a>
</div>
</form>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8"
crossorigin="anonymous"></script>
<script src="/js/scripts.js"></script>
</body>
</html>