ElasticBeanstalk can't find jsp in WEB-INF/views - Springboot

0

I'm creating a Springboot app with OAuth2, which means I need to be able to parse a login.jsp file for users to log in through. This all works locally but on EB I get 404s for all JSP targets. The OAuth endpoints work fine on EB and I can still request tokens manually but all requests that require the users to login just result in the following webpage:

There was an unexpected error (type=Not Found, status=404).
/WEB-INF/views/login.jsp

Having looked at the debug log the only difference in the logs are the following, which to me would appear to imply that path on EB is no longer valid and it can't find the src/main/webapp within which I've put WEB-INF/views/login.jsp

On localhost:

2017-01-17 23:50:15.406 DEBUG 11872 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Code archive: /home/cillian/workspace/CogTracker/target/CogTracker-0.0.1-SNAPSHOT.jar
2017-01-17 23:50:15.407 DEBUG 11872 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Code archive: /home/cillian/workspace/CogTracker/target/CogTracker-0.0.1-SNAPSHOT.jar
2017-01-17 23:50:15.407 DEBUG 11872 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Document root: /home/cillian/workspace/CogTracker/src/main/webapp

On AWS ElasticBeanstalk:

2017-01-17 23:23:12.438 DEBUG 1065 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Code archive: /var/app/current/application.jar
2017-01-17 23:23:12.440 DEBUG 1065 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Code archive: /var/app/current/application.jar
2017-01-17 23:23:12.441 DEBUG 1065 --- [           main] .t.TomcatEmbeddedServletContainerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.

So the question is, does the upload to EB require the files to be in a different location? Does the ServletContext require a specific parameter to be able to find files on EB?

For reference my WebApplicationInitializer class

public class DispatcherServletInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.scan("uk.ac");

        servletContext.addListener(new ContextLoaderListener(context));

        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }

}

and my WebMvcConfigurerAdapter:

@Configuration
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){
        configurer.enable();
    }

    @Override
    public void addViewControllers(final ViewControllerRegistry registry){
        super.addViewControllers(registry);
        registry.addViewController("/login.html");
        registry.addViewController("/welcome.html");
    }

    @Bean
    public InternalResourceViewResolver viewResolver(){
        final InternalResourceViewResolver resolver = new InternalResourceViewResolver();

        resolver.setViewClass(JstlView.class);

        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }

}
asked 7 years ago764 views
2 Answers
1

Hello,

Thank you for reaching out,
The actual deployment directory would be in the configuration and could be determined using :
grep -i "app_deploy_dir" under under /opt/elasticbeanstalk/bin/ and if you are referencing files in the app, it would be required to refer to its path, depending upon the determined value you can fix the path in the code. Thereby resolve the 404 error.

I hope the information helps. If the problem persists please feel free to reach out to me.

Regards,
Ashwin A

AWS
answered 7 years ago
profile picture
EXPERT
reviewed 2 months ago
0

aHi,
Sae here. I'm trying to deploy a war file generated from spring boot.
I'm getting same issue and i am banging my head on my computer, my head is bleeding. Seriously this issue has wasted so much of time

I did the same steps however and i'm unable to find the exact issue.Please suggest. Hopefully i get some help from you guys . The application on localhost is working fine but when i deploy it on beam stalk. error shows up

Muki
answered 6 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions