Springboot and Angularjs routes

Asked

Viewed 824 times

3

I am trying to put url friendly to take the '#' of the angle url, I followed the following tutorial: /spring-boot-as-a-backend-for-Angularjs/

and it worked in the statistical url. But if I do this

  .state('site3.evento', {//angular
              url: '/evento/:informacaoEventoId',
              templateUrl: 'tpl-site/evento.html',

//Java
@RequestMapping(/evento/{informacaoEventoId})
public String evento() {
    return "forward:index.html";
}

@Override//Spting
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations(
            "/resources/");
    registry.addResourceHandler("/**").addResourceLocations("/");

}

As the id is dynamic ai of the error, it fails to display the page the error is this:

o.s.boot.context.web.ErrorPageFilter     : Cannot forward to error page for request [/evento/208] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false

Controller

@Controller
public class RouteController implements Serializable{

private static final long serialVersionUID = 1L;

@RequestMapping({
    "/",
    "/contato",
    "/politica-de-privacidade",
    "/quem-somos",
    "/termo-de-uso",
    "/faq/teste"
})
public String index() {
    return "forward:index.html";
}

@RequestMapping("/evento/{informacaoEventoId}")
public String evento(@PathVariable String informacaoEventoId) {
    return "forward:index.html";
}

}

Spring

@Configuration
@EnableAutoConfiguration
@ComponentScan  
public class Application extends SpringBootServletInitializer {  

@Override
protected SpringApplicationBuilder configure(
        SpringApplicationBuilder application) {
    return application.sources(Application.class);
}

public static void main(String... args) {
    System.setProperty("spring.profiles.default",
            System.getProperty("spring.profiles.default", "dev"));
    @SuppressWarnings("unused")
    final ApplicationContext applicationContext = SpringApplication.run(
            Application.class, args);
    }
}

1 answer

1

The error I’m seeing is the lack of parameter definition information in the method evento. It should be noted with @PathVariable

The code should look like this:

@RequestMapping(/evento/{informacaoEventoId})
public String evento(@PathVariable String informacaoEventoId) {
    return "forward:index.html";
}
  • I did it this way and it didn’t work either, the forward is always pro index.html if it was just /Faq the forward would be pro index.html also because of the angular, but when I have to put an event id/208 here comes the error.

  • But the error is the same when you put the stop in the method?

  • No, the error is different, but I checked here was that, I have to put the param, and I did another test with a static url, put Faq/test and mapped both angular and java, and the error is the same. I think the problem ta in the configuration of Spring, I edited the question and put the spring method. vlw

  • Shows how the class is Controller, and as you call it. Pq Springboot basically doesn’t need to be configured, thus avoiding a lot of complications.

  • Try not to follow the tutorial, or do it yourself. so you might find the error. I kind of wanted to debug this code, but without much time now. vc want to pass me the server code(of course, remove your business rules and bank details, these things...)

  • vlw André, I’m not following the tutorial as you reported, I changed the Application class pro spring-boot pattern, actually I was using a lot of stuff that wasn’t needed because spring-boot already comes all configured, but I couldn’t fix it yet, At least I’m getting new ideas on how to do it. vlw

Show 1 more comment

Browser other questions tagged

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