dimanche 21 octobre 2018

Trouble setting up Spring Boot Servelet Initializer

I am trying to setup a simple web CRUD application using Spring Boot. I understand that I am supposed the spring boot servelet initializer, but in the logs, I suspect it is not running properly because it does not log what I wrote.

The end goal is for me to be able to go to localhost8080/LNU-Project/, and the home.jsp display.

Here is a link to it on github. https://github.com/rjpruitt16/LNU-Project/tree/master/src/main

WebAppInitializer.java

package com.project.LNUProject;

    import com.project.LNUProject.config.WebConfig; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet;

    import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration;

    @Slf4j 
    @SpringBootApplication 
    public class WebAppInitializer extends SpringBootServletInitializer {
        private static final String DISPATCHER_SERVLET_NAME = "dispatcher";

        public static void main(String[] args) {
            SpringApplication.run(WebAppInitializer.class, args);
        }

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

        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            log.info("onStartUp");

            // create the spring application context
            AnnotationConfigWebApplicationContext context =
                    new AnnotationConfigWebApplicationContext();
            context.register(WebConfig.class);

            // create the dispatcher servlet
            DispatcherServlet dispatcherServlet =
                    new DispatcherServlet(context);

            // register and configure the dispatcher servlet
            ServletRegistration.Dynamic registration =
                    servletContext.addServlet(DISPATCHER_SERVLET_NAME, dispatcherServlet);

            registration.setLoadOnStartup(1);
            registration.addMapping("/");
        } }




Aucun commentaire:

Enregistrer un commentaire