gpt4 book ai didi

java - 找不到符号 - Spring Boot Maven 同级作为依赖项

转载 作者:行者123 更新时间:2023-12-02 02:57:01 27 4
gpt4 key购买 nike

使用 Maven spring boot 插件重新打包没有帮助。

  1. 尝试清理 .m2 文件夹。
  2. 通过 sts 和命令行构建项目。
  3. 添加了组件扫描器来扫描实体,但在 Maven 构建本身时失败。
  4. 添加了 Spring Boot Maven 插件以重新打包为可执行 jar 选项,但似乎没有任何帮助。

父pom包含spring boot启动器

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

以及以下模块

<modules>
<module>client-data</module>
<module>eureka-server</module>
<module>eureka-client-service-1</module>
<module>eureka-client-service-2</module>
</modules>

eureka-client-service-1eureka-client-service-2client-data作为依赖。

client-dataspring-boot包类型项目jar ,添加了以下代码来创建 uber jar在客户端数据的pom.xml

     <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>

还在做mvn clean install -amd -e最终出现以下错误

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project eureka-client-service-1: Compilation failure: Compilation failure:
[ERROR] /C:/Users/balaji/trashcan/pcf-eureka-show-case/eureka-client-service-1/src/main/java/org/balaji/java/jee/pcf/eureka/client/service_1/boundary/EurekaClientEmployeesServiceEndpoint.java:[16,65] package org.balaji.java.jee.pcf.eureka.client.data.controller does not exist
[ERROR] /C:/Users/balaji/trashcan/pcf-eureka-show-case/eureka-client-service-1/src/main/java/org/balaji/java/jee/pcf/eureka/client/service_1/boundary/EurekaClientEmployeesServiceEndpoint.java:[17,61] package org.balaji.java.jee.pcf.eureka.client.data.entity does not exist
[ERROR] /C:/Users/balaji/trashcan/pcf-eureka-show-case/eureka-client-service-1/src/main/java/org/balaji/java/jee/pcf/eureka/client/service_1/boundary/EurekaClientEmployeesServiceEndpoint.java:[27,5] cannot find symbol
[ERROR] symbol: class OrganizationDataFixtureAdapter
[ERROR] location: class org.balaji.java.jee.pcf.eureka.client.service_1.boundary.EurekaClientEmployeesServiceEndpoint
[ERROR] /C:/Users/balaji/trashcan/pcf-eureka-show-case/eureka-client-service-1/src/main/java/org/balaji/java/jee/pcf/eureka/client/service_1/boundary/EurekaClientEmployeesServiceEndpoint.java:[42,32] cannot find symbol
[ERROR] symbol: class Employee
[ERROR] location: class org.balaji.java.jee.pcf.eureka.client.service_1.boundary.EurekaClientEmployeesServiceEndpoint

最佳答案

对于“有什么方法可以在不改变项目结构的情况下删除 spring-boot 行为。”的问题

=> 您可以覆盖子 pom 文件中的 spring-boot-maven-plugin 行为。

引用这里:How to add a dependency to a Spring Boot Jar in another project?

Spring Boot 1.x

  <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.20.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
...
</plugin>

Spring Boot 2.x如果您使用的是 spring-boot-starter-parent,则重新打包目标会在带有 id repackage 的执行中自动执行。在该设置中,只需指定配置,如以下示例所示:

  <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
...
</plugin>

关于java - 找不到符号 - Spring Boot Maven 同级作为依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57069796/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com