Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does spring-boot-starter-parent exactly do in pom file?

Tags:

People also ask

Why do we need spring boot starter parent?

Properties The spring-boot-starter-parent via its parent spring-boot-dependencies uses properties for configuring all the dependencies versions, Java version, and Maven plugin versions. Therefore, it makes it easy for us to control these configurations by just changing the corresponding property.

What is spring boot parent pom?

The spring-boot-starter-parent dependency is the parent POM providing dependency and plugin management for Spring Boot-based applications. It contains the default versions of Java to use, the default versions of dependencies that Spring Boot uses, and the default configuration of the Maven plugins.

What is the parent in POM xml?

A parent pom. xml file (or super POM) in Maven is used to structure the project in order to avoid redundancies and duplicate configurations by using an inheritance between different pom. xml files. If any dependency or properties are configured in both - parent and child - pom.

What is the difference between spring boot starter parent and spring boot starter web?

Difference Between Spring Boot Starter Web and Spring Boot Starter Tomcat. Spring Boot Starter Web is used for building RESTful applications using Spring MVC. Spring Boot Starter Tomcat is the default embedded container for Spring Boot Starter Web. We cannot exclude it while using web services.


I'm developing a project which is not Spring boot but also spring mvc. I mean I don't have this class for example in my project:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

I have these three classes for configuration file of spring mvc:

@Import(WebSocketConfig.class)
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "......")

public class MainConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/Content/**")
                .addResourceLocations("/Content/");
        registry.addResourceHandler("/Scripts/**")
                .addResourceLocations("/Scripts/");


    }

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver
                = new InternalResourceViewResolver();
        viewResolver.setPrefix("/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

}

Second:

public class MainInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    public static HashMap<String, String> response_code = new HashMap<String, String>();


    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] { MainConfiguration.class,
        WebSocketConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return null;
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        Security.addProvider(new BouncyCastleProvider());
        servletContext.addListener(new MainContextListener());
        System.out.println("MainInitializer.onStartup()");
}}

Third,

public class MainContextListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("Context Initialized");
        Security.addProvider(new BouncyCastleProvider());
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("Shutting down!");
    }
}

There is a controller and jsp file and I've configured it to run on tomcat webserver, something is strange for me is that when I add this snippet of code to my pom, index.jsp will appear in browser exactly but when I remove it , it gives 404 not found url for my controller. why is it that even my project is not a spring boot project need spring boot starter parent? I thought below code is related to spring boot and since my project is not spring boot but spring mvc, doesn't need it. but it has problem without this code added in pom:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
    </parent>