Spring Boot批处理-启动时出现ClassNotFoundException

时间:2019-04-03 09:36:35

标签: java maven spring-boot

我有一个带有3个spring boot子模块的spring boot项目:

  • mxm-suv- dao
  • mxm-suv- 批次
  • mxm-suv- ws

dao子模块由批处理和ws使用。

在本地(使用eclipse),我可以安装/打包或启动这些模块,一切正常。

但是,当我尝试使用java -jar在服务器中启动批处理时,我获得了“ java.lang.ClassNotFoundException:com.at.mxm.suv.dao.domain.Report”。

dao pom.xml:

<parent>
    <groupId>com.at.mxm</groupId>
    <artifactId>mxm-suv</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>mxm-suv-dao</artifactId>
<name>mxm-suv-dao</name>

<properties>
    <start-class>com.at.mxm.suv.dao.DataAccessApplication</start-class>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>exec</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

批注pom.xml:

<parent>
    <groupId>com.at.mxm</groupId>
    <artifactId>mxm-suv</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>mxm-suv-batch</artifactId>
<name>mxm-suv-batch</name>
<properties>
    <start-class>com.at.mxm.suv.batch.BatchApplication</start-class>
</properties>
<dependencies>
    <dependency>
        <groupId>com.at.mxm</groupId>
        <artifactId>mxm-suv-dao</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-quartz</artifactId>
    </dependency>
</dependencies>

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

BatchApplication.java:

@ComponentScan(basePackages = "com.at.mxm.suv.dao.*,com.at.mxm.suv.batch.*")
@SpringBootApplication
@EnableBatchProcessing
@EnableScheduling
public class BatchApplication {

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

有什么想法可能导致这种情况吗?

1 个答案:

答案 0 :(得分:0)

请参阅此git存储库。我已经制作了5个模块。