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?

bodokaiser
  • 15,122
  • 22
  • 97
  • 140

1 Answers1

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);
    }
}
OhadR
  • 8,276
  • 3
  • 47
  • 53
  • do you see spring-context in your WEB-INF\lib? need to make sure spting-boot brings it... – OhadR Oct 04 '14 at 15:18