【发布时间】:2018-12-31 15:12:36
【问题描述】:
我有一个引用外部模块来执行结果的 Spring Boot 项目。
我已经在模块依赖下添加了外部模块:
但是,当我运行 Spring Boot 应用程序时,它会失败并出现以下错误:
Error:(3, 16) java: package examples does not exist
以下源代码中的CustomerLossPrediction 引用外部模块并调用此模块失败,即使我将模块添加到项目工作区并正确添加了依赖项。
package com.example.demo.service;
import examples.CustomerLossPrediction;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
@Service
public class DL4JServiceImpl implements DL4JService {
@Override
public String fetchPrediction(MultipartFile file) throws IOException, InterruptedException {
File convFile = new File( file.getOriginalFilename());
file.transferTo(convFile);
INDArray array = new CustomerLossPrediction().generateOutput(convFile);
return array.toString();
}
}
如果需要,这里是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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-api</artifactId>
<version>0.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
</project>
我认为这是因为我试图引用某个外部模块,或者另一个无法从 Spring Boot 模块中引用?
【问题讨论】:
-
你在组件注解标签中指定了bean吗?
-
CustomerLossPrediction不是 spring bean,它是外部模块上的普通 java 类。 -
你能通过IDE运行main方法吗?就像在 IntelliJ 中打开 DemoApplication.java 文件并单击左侧栏上出现的绿色按钮
标签: java spring maven spring-boot maven-plugin