重新打包失败:使用Spring Boot Starter父版本2.1.2.0创建库时找不到主类
我在SpringSecurity中创建了一个示例资源服务器,其中包含重新打包失败:使用Spring Boot Starter父版本2.1.2.0创建库时找不到主类,spring,spring-boot,spring-security,Spring,Spring Boot,Spring Security,我在SpringSecurity中创建了一个示例资源服务器,其中包含WebSecurityConfigureAdapter。当我将库的pom中的父级spring boot starter父级从2.0.8更新到2.1.2以及spring boot maven插件时,我得到了可怕的重新打包失败:找不到主类 spring boot starter父版本的2.0.8版不存在此问题 更新:这发生在执行mvn干净编译安装时。可以找到父级为2.0.8的代码版本。只需将pom.xml spring starte
WebSecurityConfigureAdapter
。当我将库的pom中的父级spring boot starter父级从2.0.8更新到2.1.2以及spring boot maven插件
时,我得到了可怕的重新打包失败:找不到主类
spring boot starter父版本的2.0.8版不存在此问题
更新:这发生在执行mvn干净编译安装时。可以找到父级为2.0.8的代码版本。只需将pom.xml spring starter父级从2.0.8更改为2.1.2
我的图书馆pom如下
<?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.utils.security</groupId>
<artifactId>resource-config</artifactId>
<version>1.0.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-oauth2-resource-server -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-resource-server</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Web安全配置适配器
package com.example.utils.security.resource.autoconfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
@Order(PriorityOrdered.HIGHEST_PRECEDENCE + 500)
public class ResourceServerConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.anonymous().disable()
.logout().disable()
.formLogin().disable()
.httpBasic().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS).permitAll()
.anyRequest().authenticated()
.and()
.oauth2ResourceServer().jwt();
}
}
可能有两种可能性-
项目中没有main()
方法或
源目录的位置错误。您必须使用sourceSets指令来修复此问题。您的源目录应该类似于src/main/java/your/package。
发行说明中描述了这一点,以便更容易地重写重新打包
执行
上面的构造有点奇怪。如果您不希望重新打包,那么为什么要定义目标呢?只要不定义目标,重新打包就不会发生,因为当插件被明确定义时,父级只提供默认执行
如果您出于不同的原因需要定义它,那么上面的链接将解释您应该做什么。目前,您正在重新定义重新打包目标的第二次执行。我通过使用maven编译器插件
而不是spring boot maven插件
解决了这个问题。仍然要找出是什么导致了这个问题
Maven插件详细信息:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
org.apache.maven.plugins
maven编译器插件
3.6.1
1.8
1.8
您的项目中是否有main方法?您实际运行的Maven目标是什么<代码>mvn包
?或mvn spring boot:重新打包
?这可能有助于重现我正在运行的mvn clean compile安装的问题,我认为这是程序包的目标。为什么需要一个库的main方法?我可以将starter父版本更改为2.0.8,并构建它。至于目录,它确实代表了上述模式。谢谢你的评论。它帮助我认识到我不理解重新打包的目标以及如何使用springbootmaven插件
。我使用的是其他人创建的旧pom。我现在明白了,我需要使用插件的布局来安装它,这就是我修复它的原因。我只是想要一个具有源类的模块,而不需要创建可执行的jar,这就是为我做的。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>