Home > Mobile >  Start a spring boot project witout the parent part
Start a spring boot project witout the parent part

Time:03-16


I am currently working on migrating an appache CXF project to Spring BOOT.

My problem is that this project depend on two other projects and in order to import them into maven I need to declare the parent project like this:

<parent>
   <groupId>com.comapny.dd</groupId>
   <artifactId>ProjectMainJars_Parent</artifactId>
   <version>${version}</version>
 </parent>

but in order to use Spring Boot. I need to declare the parent like this:

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

I added the following code:

 <dependencyManagement>
    <dependencies>

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.4.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

    </dependencies>
  </dependencyManagement>

I still get the following error:

Exception in thread "main" java.lang.AbstractMethodError: org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.supportsSourceType(Ljava/lang/Class;)Z
    at org.springframework.context.event.GenericApplicationListenerAdapter.supportsSourceType(GenericApplicationListenerAdapter.java:81)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent(AbstractApplicationEventMulticaster.java:294)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:224)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:195)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133)

Is it possible to use spring boot without needing to change parent.
PS: I only need to create a REST service.

Thank you in advance.

CodePudding user response:

If you have to specify some other artifact as parent, then spring boot needs to be moved under dependencyManagement tag parallel to dependencies like this:

  <dependencyManagement>
    <dependencies>

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.4.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

    </dependencies>
  </dependencyManagement>

  <dependencies>
  </dependencies>

CodePudding user response:

I know it might be late but I figured out how to do it:
First make sure to clean the parent directory from any Spring dependency and then in the child project specify the following:

 <dependencyManagement>
    <dependencies>

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.4.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

    </dependencies>
  </dependencyManagement>

  <dependencies>
  </dependencies>
  • Related