Error Resolving Template "MeuTemplate", template might not exist or might not be accessible by any of the configured Resolvers SPRING Template

0

Performing an ajax request

function buscarDisciplina(){
        var codigoDisciplina = String($("#codigo").val());
        $.ajax({
            url: urlApplication+"/grade-curricular/buscar-disciplina/"+codigoDisciplina,
            type: 'GET',
            data: codigoDisciplina,
            dataType: 'JSON',
            success: function(response) {
                $("#disciplina").val(response);
            }
        });
}

Which calls the controller

@PreAuthorize("hasAuthority('PERM_GRADE_CURRICULAR_CADASTRAR')")
@RequestMapping(value = "/buscar-disciplina/{codigoDisciplina}")
public Disciplina bucarDisciplina(@PathVariable String codigoDisciplina) {
    return disciplinaService.findByCodigo(codigoDisciplina);
}

Service

public Disciplina findByCodigo(String codigo){
    return disciplinaRepository.findByCodigo(codigo);
}

Repository

public Disciplina findByCodigo(String codigo); //uso JpaRepository<Disciplina, Long>

Entity

@Size(max = 10)
@NotEmpty
@Column(name = "codigo")
private String codigo;

But when you send the requisition

It gives the error of the image above ... I have no idea what can be ....

    
asked by anonymous 20.04.2017 / 16:13

1 answer

1

The error occurs because you did not put the @ResponseBody annotation in your bucarDisciplina method. If you do not put this annotation, Thymeleaf will try to find a template with the method return.

Since you want to only return a json , just put this note indicating that the method return is the content to be displayed by the browser

Another way to do this is to set the @RequestMapping annotation as follows:

@RequestMapping(value = "/buscar-disciplina/{codigoDisciplina}", produces = MediaType.APPLICATION_JSON_VALUE)

    
17.05.2017 / 17:32