首页 > 其他分享 >spring cloud 多模块打包部署解决坑

spring cloud 多模块打包部署解决坑

时间:2022-09-03 16:12:27浏览次数:65  
标签:spring boot springframework 模块 ERROR org cloud

spring cloud 多模块打包部署解决坑

 

前置条件

笔者使用Intellij IDEA进行Spring Cloud项目创建和部署

Intellij IDEA 版本 :IntelliJ IDEA 2019.1.3 (Ultimate Edition)

Spring Cloud 版本:Spring Cloud Hoxton.SR1,该版本基于 Spring Boot 2.2.2.Release

maven 版本:3.6.3,其中setting.xml文件为原生文件

主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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.albedo</groupId>
    <artifactId>sbe1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>sbe1</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>Utf-8</project.reporting.outputEncoding>
        <java.version>11</java.version>
        <spring-cloud.version>Hoxton.SR1</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependecies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
复制代码

 

第一个坑,项目可以通过run进行启动,但是通过 mvn clean命令,报如下错误

?
123456789101112131415[INFO] Scanning for projects...[ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] Non-resolvable import POM: Failure to find org.springframework.cloud:spring-cloud-dependecies:pom:Hoxton.SR1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced @ line 44, column 25 @ [ERROR] The build could not read 1 project -> [Help 1][ERROR]   [ERROR]   The project com.albedo:sbe1:1.0-SNAPSHOT (/Users/wangzhangxiong/workspace/jproject/sbe1/pom.xml) has 1 error[ERROR]     Non-resolvable import POM: Failure to find org.springframework.cloud:spring-cloud-dependecies:pom:Hoxton.SR1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced @ line 44, column 25 -> [Help 2][ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

 该错表面是报https://repo.maven.apache.org/maven2无法加载 org.springframework.cloud:spring-cloud-dependecies:pom:Hoxton.SR1

到本地,笔者通过多种思路,其中包括,更改maven 库镜像为阿里云镜像,添加spring-milestones repository到主pom等方法,也试过降低spring cloud版本,都无法达到有效解决,最后解决办法为将

复制代码
<!--将该部分的type和scope删除-->
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependecies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
复制代码

改为

复制代码
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependecies</artifactId>
                <version>${spring-cloud.version}</version>
            </dependency>
        </dependencies>
 </dependencyManagement>
复制代码

此问题可解。

此时如果使用mvn clean或者mvn install命令,则会报错

?
1234567[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.2.RELEASE:repackage (repackage) on project spring-cloud-eureka-cluster: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.2.2.RELEASE:repackage failed: Unable to find main class -> [Help 1][ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException 

这是plugin插件的问题,此时删除spring-boot-maven-plugin插件引入即可

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

 多module一起打包问题

将主pom文件新增

<modules>
    <module>eureka-server</module>
</modules>

同时新增配置

<packaging>pom</packaging>

 

最后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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.albedo</groupId>
    <artifactId>spring-cloud-eureka-cluster</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>spring-cloud-eureka-cluster</name>
    <packaging>pom</packaging>
    <description>Demo project for Spring Boot</description>
    <modules>
        <module>eureka-server</module>
    </modules>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>Utf-8</project.reporting.outputEncoding>
        <java.version>8</java.version>
        <spring-cloud.version>Hoxton.SR1</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependecies</artifactId>
                <version>${spring-cloud.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>
复制代码

 

https://www.cnblogs.com/wangzxblog/p/12395879.html

标签:spring,boot,springframework,模块,ERROR,org,cloud
From: https://www.cnblogs.com/sunny3158/p/16652858.html

相关文章

  • 4.2 安装与配置mysql模块
    在使用mysql模块操作mysql数据库之前,必须先对mysql模块进行必要的配置步骤如下:constmysql=require('mysql')constdb=mysql.createPool({host:'127.0.0.1......
  • SpringBoot集成Dubbo和Zookeeper
    15、SpringBoot集成Dubbo和Zookeeper15.1、分布式理论什么是分布式系统?在《分布式系统原理与范型》一书中有如下定义:“分布式系统是若干独立计算机的集合,这些计算机对......
  • Docker基础知识 (8) - 使用 Docker 部署 SpringBoot + MariaDB(MySQL)项目
    本文在“ Docker基础知识(7)-使用Docker部署SpringBoot项目”里的SpringbootWebDocker项目的基础上,添加JDBC、MariaDB和MyBatis相关依赖包和数据库操作代......
  • SpringSecurity - 企业应用的安全框架
    参考资料1、官方网站:https://docs.spring.io/spring-security/reference/index.html认证(Authentication)用户认证:验证某个用户是否为系统中的合法主体,也就是说用户能否访......
  • CVE-2022-22978 Spring-Security 漏洞复现
    1说明在SpringSecurity中使用RegexRequestMatcher且规则中包含带点号的正则表达式时,攻击者可以通过构造恶意数据包绕过身份认证2环境搭建环境搭建地址可以参考如下的......
  • springboot项目打jar包运行出现乱码
    springboot项目打jar包运行出现乱码1、控制台乱码在运行程序之前,执行chcp65001,即可将控制台切换到utg8编码格式,之后在继续运行jar包即可。chcp650012、数据库乱码......
  • Spring 中使用自定义的 ThreadLocal 存储导致的坑
    Spring中有时候我们需要存储一些和Request相关联的变量,例如用户的登陆有关信息等,它的生命周期和Request相同。一个容易想到的实现办法是使用ThreadLocal:pub......
  • SpringBoot 异步输出 Logback 日志
    一、介绍1.1LogbackLogback是由log4j创始人设计的另一个开源日志组件,它分为下面下个模块:logback-core:其它两个模块的基础模块logback-classic:它是log4......
  • 阿里druid-spring-boot-starter 配置,个人整理以及遇到的问题(防止之后找不到)
    ​简介,什么是DruidDruid是阿里巴巴开源平台上的一个项目,整个项目由数据库连接池、插件框架和SQL解析器组成。该项目主要是为了扩展JDBC的一些限制,可以让程序员实现一些......
  • SpringMVC 07: WEB-INF下的资源访问 + SpringMVC拦截器
    WBE-INF目录下的资源访问项目配置和Spring博客集(指SpringMVC02)中配置一样出于对网站资源的安全性保护,放在WBE-INF目录下的资源不可以被外部直接访问在WEB-INF/......