3

I am wiring a AngularJS and spring-boot application together by hand for the first time. The issues I am running into is my @RestController is not returning the index page:

@RestController
public class IndexController {

    @RequestMapping("/")
    public String index(){
        System.out.println("Looking in the index controller.........");
        return "index";
    }

}

Directory:

enter image description here

It keeps rendering the default 404 error page:

enter image description here

----------------UPDATE 1------------------

I have added a configuration file:

@Configuration
public class IndexPageConfiguration {

    @Bean
    public InternalResourceViewResolver viewResolver(){

        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/app/");
        resolver.setSuffix(".html");
        return resolver;

    }

}

RestController

@RestController
public class IndexController {

    @RequestMapping("/")
    public String index(){
        System.out.println("Looking in the index controller.........");
        return "index";
    }

}

main class:

@SpringBootApplication(scanBasePackages = { "com.serviceImpl","com.service","com.config" },exclude = { ErrorMvcAutoConfiguration.class })
public class SpringCrudApplication {

    public static void main(String[] args) {

        SpringApplication.run(SpringCrudApplication.class, args);
    }
}

The above main class is still returning the default 404 error page.

2 Answers 2

2

On the other hand, Spring will automatically look for the index.html page if you put it directly under webapp folder. So you don't need any configuration.

This is just another way to do it.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to configure InternalRosourceViewResolver to let the spring know your jsp location

@Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/app/");
        resolver.setSuffix(".html");
        return resolver;

    }

So Spring will append and append location and suffix to your View returned.

I think it is good idea to keep your views separately in any other folder and configure your folder location according to it.

If you want to continue with your current set up

you should return "/app/index.html" from your controller.

Spring boot provides White label error page to hide your stack trace when a Server side error/ exception occurs, this will help us from protecting our code from intruders. If you want to get rid of white label error.

In your @SpringBootApplication specify excludes ErrorMvcAutoConfiguration.class

@SpringBootApplication(scanBasePackages = { "com.ekart.app" }, exclude = { ErrorMvcAutoConfiguration.class })

If you are not using @SpringBootApplication annotatio, you should supply same same excludes in @EnableAutoConfiguration annotation

9 Comments

@Drew1208 try removing while label error. and also remove spring security from your pom.xml because spring boot will autoconfigure spring security
@Drew1208 don't do both, either return "index" if you place IRVR, otherwise return "/app/index.html"
@Pranani Kinnera I am not using spring security at the moment.
GOT IT.... Thank you. I needed to do what you suggested and add scan my rest controller. However it is just rendering "index" not the index.html page what is tied into my angularJS
@Drew1208 I have edited your question, with what is need to do. please follow that edit
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.