tleveque
tleveque

Reputation: 547

Using Spring Boot without the parent POM doesn't work

I am trying the simple sample from the SpringBoot QuickStart (http://projects.spring.io/spring-boot/#quick-start). Using the spring-boot-starter-parent as the parent is working fine. I can run the sample without any problems. But I absolutely need to use my own parent pom. So I read the documentation : http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-without-a-parent

I tried it. It compiled fine. But crashes at run time. Here is my configuration. In my parent pom:

<dependencyManagement>
    <dependencies>
    ....
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.1.5.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    ....
    </dependencies>
</dependencyManagement>

In my pom:

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

But when I run the application, I get this:


    2014-08-11 12:50:29.275 ERROR 28474 --- [           main] o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalStateException: Failed to introspect annotations: class com.imetrik.oaas.tool.application.springboottest.SampleController.SampleController
    at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:169)
    at org.springframework.core.annotation.AnnotatedElementUtils.isAnnotated(AnnotatedElementUtils.java:75)
    at org.springframework.core.type.StandardAnnotationMetadata.isAnnotated(StandardAnnotationMetadata.java:102)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:138)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:128)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:123)
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:159)
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:135)
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:127)
    at org.springframework.boot.SpringApplication.load(SpringApplication.java:620)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
    at com.imetrik.oaas.tool.application.springboottest.SampleController.SampleController.main(SampleController.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:673)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:480)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:306)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:241)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3178)
    at java.lang.Class.getAnnotations(Class.java:3158)
    at org.springframework.core.annotation.AnnotatedElementUtils.doProcess(AnnotatedElementUtils.java:195)
    at org.springframework.core.annotation.AnnotatedElementUtils.doProcess(AnnotatedElementUtils.java:212)
    at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:165)
    ... 18 common frames omitted

Exception in thread "main" java.lang.IllegalStateException: Failed to introspect annotations: class com.imetrik.oaas.tool.application.springboottest.SampleController.SampleController
    at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:169)
    at org.springframework.core.annotation.AnnotatedElementUtils.isAnnotated(AnnotatedElementUtils.java:75)
    at org.springframework.core.type.StandardAnnotationMetadata.isAnnotated(StandardAnnotationMetadata.java:102)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:138)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:128)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:123)
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:159)
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:135)
    at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:127)
    at org.springframework.boot.SpringApplication.load(SpringApplication.java:620)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
    at com.imetrik.oaas.tool.application.springboottest.SampleController.SampleController.main(SampleController.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:673)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:480)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:306)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:241)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3178)
    at java.lang.Class.getAnnotations(Class.java:3158)
    at org.springframework.core.annotation.AnnotatedElementUtils.doProcess(AnnotatedElementUtils.java:195)
    at org.springframework.core.annotation.AnnotatedElementUtils.doProcess(AnnotatedElementUtils.java:212)
    at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:165)
    ... 18 more

Process finished with exit code 1

I have no clue how to solve this. I tried putting the dependencyManagement directly in my pom (not in the parent). Same result. I did search here on stackoverflow and elsewhere, but I cannot find a single working example. We are using Maven 3.0.4 and Java 1.7U51

Upvotes: 7

Views: 14281

Answers (2)

Chethan
Chethan

Reputation: 311

I may be late but I am sure it will be helpful to everyone who wants to run SpringBoot without inheriting from parent. It was very frustrating to figure the following but it finally it worked for me!

Basically,

  1. Intellij maven auto-import was turned off. Enabled it.
  2. I have to add spring-boot dependencies manually. i.e if you just inherit spring-boot as parent, you will be given a default set of dependencies to work on. But when you don't inherit you have to declare those dependencies manually in pom.xml
  3. If you observe pom.xml, "spring-boot-dependencies" has to be in its own <dependencyManagement> tag. If you combine all of the dependencies in a single <dependencies>, then references are lost in the code!
  4. See the following example:

pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>Chethan</artifactId>
        <groupId>groupId</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>myspringbootwithoutparent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.4.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build> </project>

ApplicationWithoutParentPom.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chethanshankar on 10/18/16.
 */
@RestController
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class ApplicationWithoutParentPom {
    @RequestMapping("/")
    String home() {
        return "Hello World without SPRING BOOT AS PARENT!!!";
    }

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

Errors

java: error: release version 5 not supported

When compiling the project you may get this error

java: error: release version 5 not supported

Module todolist SDK 17 does not support source version 1.5. 
Possible solutions:
- Downgrade Project SDK in settings to 1.5 or compatible. Open project settings.
- Upgrade language version in Maven build file to 17. Update pom.xml and reload the project.

You can fix by adding inside the <properties> the maven compiler version, in my case for Java 17

 <properties>
        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
</properties>

Upvotes: 16

tleveque
tleveque

Reputation: 547

The problem was that my parent pom was dependent on Spring 3.2.5. And I find out that Spring-Boot 1.5.x needs at least Spring 4. This is not clearly defined on the Spring-Boot page.

Upvotes: 1

Related Questions