12
respostas

Vraptor não encontra meu Controller quando uso minha entidade(usuarioTO)

Galera, fiz um projeto com Vraptor 4.2.0-RC3, usando maven pra gerenciar minhas dependências, quando eu declaro um método que chama uma classe entidade, o vraptor para de achar meu controller, alguem sabe o que pode ser? abaixo minha classe controller e minha classe entidade.

package br.com.trust.ctms.controller;

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.trust.ctms.UsuarioTO;

@Controller
public class LoginController {

    private final Result result;

    @Inject
    public LoginController(Result result){
        this.result = result;
    }

    @Deprecated
    public LoginController(){
        this(null);
    }

    @Get("/")
    public void login(){
        System.out.println("Login");
    }

    /*
    @Post("/efetuarlogin")
    public void efetuarLogin(UsuarioTO usuario){

        if(usuario.getNome().equals("marcelo") && usuario.getSenha().equals("marcelo")){
            System.out.println("usuario: " + usuario.getNome() + " senha: " + usuario.getSenha());
            this.result.redirectTo(HomeController.class).home();

        }
        else{
            this.result.redirectTo(this).login();
        }

    }*/

}

Quando declaro esse meu método, o vraptor não encontra meu controller:

@Post("/efetuarlogin")
    public void efetuarLogin(UsuarioTO usuario){

        if(usuario.getNome().equals("marcelo") && usuario.getSenha().equals("marcelo")){
            System.out.println("usuario: " + usuario.getNome() + " senha: " + usuario.getSenha());
            this.result.redirectTo(HomeController.class).home();

        }
        else{
            this.result.redirectTo(this).login();
        }

    }

Minha classe entidade usuarioTO:

package br.com.trust.ctms;

public class UsuarioTO {

    String nome;
    String senha;

    public UsuarioTO(String nome,String senha) {
        this.nome = nome;
        this.senha = senha;
    }

    public String getNome() {
        return nome;
    }
    public void setNome(String nome) {
        this.nome = nome;
    }
    public String getSenha() {
        return senha;
    }
    public void setSenha(String senha) {
        this.senha = senha;
    }

}
12 respostas

Bom Marcelo, provavelmente o problema não é o argumento que vc está recebendo. Como que vc está tentando acessar o endereço /efetuaLogin ? Acho que deve haver com alguma configuração de rota aí.

Tudo bem Alberto? então...

Quando eu subo o meu tomcat ele não acha meu controller, e quando eu comento esse metodo efetuarlogin ele reconhece, segue o log de start do tomcat com meu metodo ativo:

16:48:27,542 INFO [DefaultConverters ] Registering bundled converters 16:48:27,569 INFO [DefaultConverters ] Registering bundled converters 16:48:27,572 DEBUG [DefaultConverters ] Unable to find a converter for long. Returning NullConverter. 16:48:27,572 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.PrimitiveLongConverter to long 16:48:27,573 DEBUG [DefaultConverters ] Unable to find a converter for double. Returning NullConverter. 16:48:27,573 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.PrimitiveDoubleConverter to double 16:48:27,573 DEBUG [DefaultConverters ] Unable to find a converter for class java.math.BigDecimal. Returning NullConverter. 16:48:27,573 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.BigDecimalConverter to class java.math.BigDecimal 16:48:27,579 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Short. Returning NullConverter. 16:48:27,579 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.ShortConverter to class java.lang.Short 16:48:27,580 DEBUG [DefaultConverters ] Unable to find a converter for class java.util.Calendar. Returning NullConverter. 16:48:27,580 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.CalendarConverter to class java.util.Calendar 16:48:27,621 DEBUG [ControllerHandler ] Found controller: {ControllerClass br.com.trust.ctms.controller.IndexController} 16:48:27,703 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.IndexController.index() as [] 16:48:27,703 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.IndexController.index() as [] 16:48:27,704 DEBUG [DefaultParametersControl] For /index retrieved /index with {} 16:48:27,705 INFO [DefaultRouteBuilder ] /index [GET] -> public void br.com.trust.ctms.controller.IndexController.index() 16:48:27,708 DEBUG [DefaultConverters ] Unable to find a converter for interface br.com.caelum.vraptor.observer.upload.UploadedFile. Returning NullConverter. 16:48:27,708 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.observer.upload.UploadedFileConverter to interface br.com.caelum.vraptor.observer.upload.UploadedFile 16:48:27,708 DEBUG [DefaultConverters ] Unable to find a converter for short. Returning NullConverter. 16:48:27,708 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.PrimitiveShortConverter to short 16:48:27,709 DEBUG [ControllerHandler ] Found controller: {ControllerClass br.com.trust.ctms.controller.HomeController} 16:48:27,711 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.HomeController.home() as [] 16:48:27,711 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.HomeController.home() as [] 16:48:27,711 DEBUG [DefaultParametersControl] For /home retrieved /home with {} 16:48:27,712 INFO [DefaultRouteBuilder ] /home [GET] -> public void br.com.trust.ctms.controller.HomeController.home() 16:48:27,712 DEBUG [DefaultConverters ] Unable to find a converter for char. Returning NullConverter. 16:48:27,712 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.PrimitiveCharConverter to char 16:48:27,713 DEBUG [DefaultConverters ] Unable to find a converter for class java.math.BigInteger. Returning NullConverter. 16:48:27,713 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.BigIntegerConverter to class java.math.BigInteger 16:48:27,732 DEBUG [InterceptorStereotypeHandler] Found interceptor for class br.com.trust.ctms.controller.AccessInterceptor 16:48:27,734 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Long. Returning NullConverter. 16:48:27,734 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.LongConverter to class java.lang.Long 16:48:27,735 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Enum. Returning NullConverter. 16:48:27,735 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.EnumConverter to class java.lang.Enum 16:48:27,735 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Boolean. Returning NullConverter. 16:48:27,735 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.BooleanConverter to class java.lang.Boolean 16:48:27,736 DEBUG [InterceptorStereotypeHandler] Found interceptor for class br.com.caelum.vraptor.interceptor.FlashInterceptor 16:48:27,736 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Double. Returning NullConverter. 16:48:27,736 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.DoubleConverter to class java.lang.Double 16:48:27,737 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Float. Returning NullConverter. 16:48:27,737 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.FloatConverter to class java.lang.Float 16:48:27,737 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Byte. Returning NullConverter. 16:48:27,737 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.ByteConverter to class java.lang.Byte 16:48:27,739 DEBUG [DefaultConverters ] Unable to find a converter for class java.util.Date. Returning NullConverter. 16:48:27,739 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.DateConverter to class java.util.Date 16:48:27,739 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.String. Returning NullConverter. 16:48:27,739 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.StringConverter to class java.lang.String 16:48:27,740 DEBUG [DefaultConverters ] Unable to find a converter for byte. Returning NullConverter. 16:48:27,740 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.PrimitiveByteConverter to byte 16:48:27,740 DEBUG [DefaultConverters ] Unable to find a converter for boolean. Returning NullConverter. 16:48:27,740 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.PrimitiveBooleanConverter to boolean 16:48:27,741 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Character. Returning NullConverter. 16:48:27,741 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.CharacterConverter to class java.lang.Character 16:48:27,741 DEBUG [DefaultConverters ] Unable to find a converter for class java.lang.Integer. Returning NullConverter. 16:48:27,741 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.IntegerConverter to class java.lang.Integer 16:48:27,742 DEBUG [DefaultConverters ] Unable to find a converter for int. Returning NullConverter. 16:48:27,742 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.PrimitiveIntConverter to int 16:48:27,742 DEBUG [DefaultConverters ] Unable to find a converter for float. Returning NullConverter. 16:48:27,742 DEBUG [DefaultConverters ] adding converter class br.com.caelum.vraptor.converter.PrimitiveFloatConverter to float 16:48:27,743 DEBUG [InterceptorStereotypeHandler] Found interceptor for class br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor 16:48:27,753 DEBUG [InterceptorStackHandlersCache] Caching br.com.trust.ctms.controller.AccessInterceptor 16:48:27,768 DEBUG [InterceptorStackHandlersCache] Caching br.com.caelum.vraptor.interceptor.FlashInterceptor 16:48:27,768 DEBUG [InterceptorStackHandlersCache] Caching br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor 16:48:27,768 INFO [VRaptor ] VRaptor 4.2.0-RC3 successfuly initialized

Vamos la, Marcelo peço que quando for postar códigos utilize o botão "inserir código" para que fique mais fácil a visualização.

Essa classe UsuarioTO é uma tabela do banco de dados ?

Matheus! Mal cara, qdo vi ja tinha enviado, nao pude arrumar.

Entao essa minha classe é somente 1 entidade, mas nao uso ela pra persistir os dados, nao uso hibernate, tenho um projeto jdbc flexivel que faz isso, esse usuarioTo é um java bean somente.

Isso que vc precisava saber?

Exato, ta muito estranho a saída do console do seu projeto, você utiliza tomcat ?

Tente retirar o UsuarioTO como parâmetro do método e instancia-lo dentro do método.

@Post("/efetuarlogin")
    public void efetuarLogin(){
    UsuarioTO usuario = new UsuarioTO("marcelo", "marcelo");
        if(usuario.getNome().equals("marcelo") && usuario.getSenha().equals("marcelo")){
            System.out.println("usuario: " + usuario.getNome() + " senha: " + usuario.getSenha());
            this.result.redirectTo(HomeController.class).home();

        }
        else{
            this.result.redirectTo(this).login();
        }

    }

Só para a gente testar

Estou usando o tomcat 7, e esse usuario que recebo como parametro vem do meu jsp, que envio via form method post, recebendo no meu controller. Como eu faria pra pegar os valores sem receber por parametro?

Consegue mandar a aplicação zipada para mim ? Fica bem mais fácil para eu dar uma olhada.

Claro! Amanha logo cedo te envio, qual email?

So um detalhe matheus, isso funcionava, parou de funcionar qdo coloquei minhas classes java bean em outro module do maven, mas te mando o projeto.

matheushcastiglioni@gmail.com

Ta muito estranho, nunca aconteceu isso comigo, quero dar uma olhada com detalhes.

Matheus, blz cara? te mandei o projeto, qdo puder veja se consegue descobrir a merda que eu fiz.rs

fiz um teste trocando o paramentor do meu metodo, não utilizando minha entidade.

E funcionou, meu vraptor encontrou meu controller.

@Post("/efetuarlogin")
    public void efetuarLogin(String nome,String senha){

        if(nome.equals("marcelo") && senha.equals("marcelo")){
            System.out.println("usuario: " + nome + " senha: " + senha);
            this.result.redirectTo(HomeController.class).home();

        }
        else{
            this.result.redirectTo(this).login();
        }

    }
16:13:17,769  INFO [DefaultConverters   ] Registering bundled converters
16:13:17,785  INFO [DefaultConverters   ] Registering bundled converters
16:13:17,789 DEBUG [DefaultConverters   ] Unable to find a converter for long. Returning NullConverter.
16:13:17,789 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.PrimitiveLongConverter to long
16:13:17,790 DEBUG [DefaultConverters   ] Unable to find a converter for double. Returning NullConverter.
16:13:17,790 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.PrimitiveDoubleConverter to double
16:13:17,790 DEBUG [DefaultConverters   ] Unable to find a converter for class java.math.BigDecimal. Returning NullConverter.
16:13:17,790 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.BigDecimalConverter to class java.math.BigDecimal
16:13:17,798 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Short. Returning NullConverter.
16:13:17,798 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.ShortConverter to class java.lang.Short
16:13:17,842 DEBUG [ControllerHandler   ] Found controller: {ControllerClass br.com.trust.ctms.controller.LoginController}
16:13:17,906 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.LoginController.login() as []
16:13:17,907 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.LoginController.login() as []
16:13:17,909 DEBUG [DefaultParametersControl] For / retrieved / with {}
16:13:17,909  INFO [DefaultRouteBuilder ] /                                                 [GET] -> public void br.com.trust.ctms.controller.LoginController.login()
16:13:17,917 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.LoginController.efetuarLogin(java.lang.String,java.lang.String) as [nome, senha]
16:13:17,917 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.LoginController.efetuarLogin(java.lang.String,java.lang.String) as [nome, senha]
16:13:17,918 DEBUG [DefaultParametersControl] For /efetuarlogin retrieved /efetuarlogin with {}
16:13:17,918  INFO [DefaultRouteBuilder ] /efetuarlogin                                     [POST] -> public void br.com.trust.ctms.controller.LoginController.efetuarLogin(java.lang.String,java.lang.String)
16:13:17,920 DEBUG [DefaultConverters   ] Unable to find a converter for class java.util.Calendar. Returning NullConverter.
16:13:17,920 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.CalendarConverter to class java.util.Calendar
16:13:17,920 DEBUG [ControllerHandler   ] Found controller: {ControllerClass br.com.trust.ctms.controller.IndexController}
16:13:17,921 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.IndexController.index() as []
16:13:17,921 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.IndexController.index() as []
16:13:17,921 DEBUG [DefaultParametersControl] For /index retrieved /index with {}
16:13:17,922  INFO [DefaultRouteBuilder ] /index                                            [GET] -> public void br.com.trust.ctms.controller.IndexController.index()
16:13:17,922 DEBUG [DefaultConverters   ] Unable to find a converter for interface br.com.caelum.vraptor.observer.upload.UploadedFile. Returning NullConverter.
16:13:17,922 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.observer.upload.UploadedFileConverter to interface br.com.caelum.vraptor.observer.upload.UploadedFile
16:13:17,923 DEBUG [DefaultConverters   ] Unable to find a converter for short. Returning NullConverter.
16:13:17,923 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.PrimitiveShortConverter to short
16:13:17,923 DEBUG [ControllerHandler   ] Found controller: {ControllerClass br.com.trust.ctms.controller.HomeController}
16:13:17,924 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.HomeController.home() as []
16:13:17,924 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for public void br.com.trust.ctms.controller.HomeController.home() as []
16:13:17,924 DEBUG [DefaultParametersControl] For /home retrieved /home with {}
16:13:17,924  INFO [DefaultRouteBuilder ] /home                                             [GET] -> public void br.com.trust.ctms.controller.HomeController.home()
16:13:17,925 DEBUG [DefaultConverters   ] Unable to find a converter for char. Returning NullConverter.
16:13:17,925 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.PrimitiveCharConverter to char
16:13:17,925 DEBUG [DefaultConverters   ] Unable to find a converter for class java.math.BigInteger. Returning NullConverter.
16:13:17,926 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.BigIntegerConverter to class java.math.BigInteger
16:13:17,945 DEBUG [InterceptorStereotypeHandler] Found interceptor for class br.com.trust.ctms.controller.AccessInterceptor
16:13:17,948 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Long. Returning NullConverter.
16:13:17,948 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.LongConverter to class java.lang.Long
16:13:17,948 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Enum. Returning NullConverter.
16:13:17,948 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.EnumConverter to class java.lang.Enum
16:13:17,949 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Boolean. Returning NullConverter.
16:13:17,949 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.BooleanConverter to class java.lang.Boolean
16:13:17,949 DEBUG [InterceptorStereotypeHandler] Found interceptor for class br.com.caelum.vraptor.interceptor.FlashInterceptor
16:13:17,949 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Double. Returning NullConverter.
16:13:17,950 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.DoubleConverter to class java.lang.Double
16:13:17,950 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Float. Returning NullConverter.
16:13:17,950 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.FloatConverter to class java.lang.Float
16:13:17,950 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Byte. Returning NullConverter.
16:13:17,951 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.ByteConverter to class java.lang.Byte
16:13:17,954 DEBUG [DefaultConverters   ] Unable to find a converter for class java.util.Date. Returning NullConverter.
16:13:17,954 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.DateConverter to class java.util.Date
16:13:17,954 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.String. Returning NullConverter.
16:13:17,954 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.StringConverter to class java.lang.String
16:13:17,955 DEBUG [DefaultConverters   ] Unable to find a converter for byte. Returning NullConverter.
16:13:17,955 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.PrimitiveByteConverter to byte
16:13:17,955 DEBUG [DefaultConverters   ] Unable to find a converter for boolean. Returning NullConverter.
16:13:17,955 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.PrimitiveBooleanConverter to boolean
16:13:17,955 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Character. Returning NullConverter.
16:13:17,955 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.CharacterConverter to class java.lang.Character
16:13:17,956 DEBUG [DefaultConverters   ] Unable to find a converter for class java.lang.Integer. Returning NullConverter.
16:13:17,956 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.IntegerConverter to class java.lang.Integer
16:13:17,956 DEBUG [DefaultConverters   ] Unable to find a converter for int. Returning NullConverter.
16:13:17,956 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.PrimitiveIntConverter to int
16:13:17,957 DEBUG [DefaultConverters   ] Unable to find a converter for float. Returning NullConverter.
16:13:17,957 DEBUG [DefaultConverters   ] adding converter class br.com.caelum.vraptor.converter.PrimitiveFloatConverter to float
16:13:17,957 DEBUG [InterceptorStereotypeHandler] Found interceptor for class br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor
16:13:17,968 DEBUG [InterceptorStackHandlersCache] Caching br.com.trust.ctms.controller.AccessInterceptor 
16:13:17,983 DEBUG [InterceptorStackHandlersCache] Caching br.com.caelum.vraptor.interceptor.FlashInterceptor 
16:13:17,983 DEBUG [InterceptorStackHandlersCache] Caching br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor 
16:13:17,983  INFO [VRaptor             ] VRaptor 4.2.0-RC3 successfuly initialized

Beleza, eu dou uma olhada.