Vraptor: conflict of routes

Asked

Viewed 188 times

1

I am developing a news system for a client, and I am going through a difficulty, at the moment that I will record the news at the bank, the following message:

java.lang.Illegalstateexception: There are two Rules that Matches the Uri '/noticias/persistir' with method POST: [Fixedmethodstrategy: /noticias/{listaUltimasNoticias} mais [POST]], [Fixedmethodstrategy: /noticias/persistir persist [POST]] with same Priority. Consider using @Path Priority attribute.

In my controller the persist method is like this:

Noticiascontroller.java

@Post("/noticias/persistir")
public void persistir(Noticia noticia){
     [...]
}

And my edit or insert form is like this:

<form action="<c:url value='/noticias/persistir'/>" method="post"
            class="form-horizontal" role="form">

      <input type="hidden" class="form-control" placeholder=""
                name="noticia.tipo" value="Noticia"/> 
//corpo do formulário tudo correto

</form>

This form if inserting and editing has already worked, but started pointing out this error, what can it be? And how do I correct?

  • Considered using in controller @Path("/noticias/persistir")??

  • @Wellingtonavelino I considered and tried to do but the msm error occurs

  • You have created some other route with this same parameter @Post("/noticias/persistir") if created try to pass a type id {noticias.id}/persisitr

  • @Wellingtonavelino I did not create another route with this parameter, as I said, before it was running right, now started to appear this error ae, without me changing the controller and the form

1 answer

4


all right? The mistake itself gives you a good hint. The following two routes conflict:

/noticias/{listaUltimasNoticias} e noticias/persisti

the problem is that the first receives a variable as a parameter, and as it is a variable, {listaUltimasNoticias} can be anything, including persisti which is the suffix of the second path. Some alternatives to solve are:

1) change either of the two routes, of course

2) set priority in your path. For example:

@Post @Path(value='/noticias/persisti', priority=HIGHEST) public void seuMetodo() {...}

You find a complete explanation, with an example in: http://www.vraptor.org/pt/docs/controllers-rest/#prioritizing-for-your-paths

  • hehe, nothing like one of the commiters responding!

Browser other questions tagged

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