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

spring-boot-starter-parent github
spring-boot-starter-parent jar
spring-boot-starter for a spring batch application is
spring-boot maven plugin
error in spring-boot-starter-parent
spring boot started parent maven
spring-boot-starter-parent not found
spring-boot parent latest version maven

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>

It provides place for common configuration for CHILD POMs. for e.g.

Dependencies & Properties

For e.g. Here is the parent POM configuration 1.4.2.RELEASE spring-boot-dependencies which is parent of spring-boot-starter-parent

<properties>
    <activemq.version>5.13.4</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    <appengine.version>1.9.44</appengine.version>
    <artemis.version>1.3.0</artemis.version>
    <aspectj.version>1.8.9</aspectj.version>
    <assertj.version>2.5.0</assertj.version>
    <atomikos.version>3.9.3</atomikos.version>
    <bitronix.version>2.1.4</bitronix.version>
    <caffeine.version>2.3.4</caffeine.version>

common properties for child POMs

<dependencyManagement>
    <dependencies>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <version>1.4.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <type>test-jar</type>
            <version>1.4.2.RELEASE</version>
        </dependency>
        <dependency>

common dependencies for childs

Spring-boot-starter-parent Example, We can always get the latest version of spring-boot-starter-parent from Maven will download jar files based on the version defined for starter  So based on the above understanding, spring boot also requires parent declarations to define all spring boot dependencies into the project. It inherits dependency management from spring-boot-dependencies. You should only need to specify the Spring Boot version number on this dependency.

If you can provide more informations, like your pom integrality, we can look futher to inderstand and help you more.

In the other hand, the parent pom spring-boot-starter-parent, contains the full dependencies(mvc, cache, jpa) and commons properties to maintain dependencies versions in a good consistency, to be used in your project or/and submodules.

Basically, you can add some starters in your pom.xml depending on your need (web, jpa, batch....) For your example, you can just add a starter mvc to your pom.xml without adding other dependencies, so your pom.xml can just be like that :

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<properties>
    <java.version>1.8</java.version>
</properties>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The Spring Boot Starter Parent, We have seen that spring-boot application pom.xml has parent declaration as shown in the below pom.xml file. Why do we need that? ? Spring Boot Starter Parent plays a key role in managing dependency versions and having the right plug-ins configured. Key goal of Spring Boot is to enable a quick start to developing production ready applications.

Spring Boot provides a number of "Starters" that let you add jars to your classpath. For ex. spring-boot-starter-security,spring-boot-starter-web etc. The "spring-boot-starter-parent" is a special starter that provides useful Maven defaults i.e it adds all the required jars and other things automatically. It also provides a dependency-management section so that you can omit version tags for dependencies you are using in pom.xml. For ex. suppose you want to create web application with spring boot so you need to add the following.

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

Now note here that tag is omitted. So ultimately the "spring-boot-starter-parent" adds so many things by default so we no need to worry about those things.

What is spring-boot-starter-parent in Spring-Boot pom.xml file , Default java version is 1.6. A project can override this by specifying a property <​java.version>1.8</java.version> in the project pom. A few  What does Spring Boot Starter Parent inherit from spring-boot-dependencies? What is the Spring Boot Starter Parent and How to use it? All Spring Boot projects typically use spring-boot-starter-parent as the parent in pom.xml .

Introduction to Spring Boot Starter Parent – Spring Boot Tutorial, Typically, your Maven POM file inherits from the spring-boot-starter-parent If you do not already have Gradle installed, you can follow the instructions at Spring Boot CLI source code to understand exactly how customizations are applied. 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.

Spring Boot Reference Documentation, You can use Spring Boot to create Java applications that can be Typically, your Maven POM file inherits from the spring-boot-starter-parent  All Spring Boot projects typically use spring-boot-starter-parent as the parent in pom.xml. spring-boot-starter-paren allows us to manage the following things for multiple child projects and modules: Configuration - Java Version and Other Properties Dependency Management - Version of dependencies

Getting Started, Spring Boot starter parent is a convenient and easy way for dependency management. typically you may have seen following entry in the pom.xml file: Once this configuration is in place, we can start adding Spring  Spring Boot Starter Parent. Parent pom providing dependency and plugin management for applications built with Maven. Spring Releases (1) Spring Plugins (38) Spring Lib M (2) Spring Milestones (2) JBoss Public (6) SpringFramework (1)

Comments
  • my question is that my project is not a spring boot project. but when I remove spring-boot-starter-parent from dependencies, index.jsp give 404 error. why is it that?