0

I am new to spring and trying to write a pom.xml file to be executed with mvn exec:java.

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.satisfeet</groupId>
    <artifactId>app</artifactId>
    <version>0.0.0</version>

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

    <properties>
        <start-class>com.satisfeet.Application</start-class>
        <java.version>1.8</java.version>
    </properties>

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

My directory structure is:

/src
  |_ /main
      |__ /java
           |__ /com
                |__ /satisfeet
                     |__ /core
                     |__ /http
                     |__ Application.java

When I now run mvn package or mvn exec:java I get first a warning:

java.lang.ClassNotFoundException: com.satisfeet.Application
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
    at java.lang.Thread.run(Thread.java:745)

which then results in:

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project app: An exception occured while executing the Java class. com.satisfeet.Application -> [Help 1]

which I do not understand as the Application.java file should be correct:

package com.satisfeet;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;

import com.satisfeet.http.CustomerController;

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

What did I miss?

5
  • 1
    Did you have a look here? Commented Oct 4, 2014 at 8:57
  • @John yes but I was not able to transfer the answer to my case. I am confused with the extra build plugin definitions. Commented Oct 4, 2014 at 9:27
  • 2
    You need to have the spring-boot-maven-plugin shown at spring.io/guides/gs/spring-boot Commented Oct 4, 2014 at 10:05
  • @geond yes this was the problem and I needed to call mvn spring:boot Commented Oct 4, 2014 at 14:59
  • @geond Do you add an answer? Commented Oct 4, 2014 at 15:00

1 Answer 1

0

Have a look at Spring docs about how to use the @ComponentScan - you should give it param, which is the package you want Spring to scan.

package com.satisfeet;

@Configuration
@ComponentScan("com.satisfeet")
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

do you see spring-context in your WEB-INF\lib? need to make sure spting-boot brings it...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.