此处将为大家介绍关于为什么从SpringBoot版本2.1.4更改为2.1.5会给出未知的配置Maven错误?的详细内容,并且为您解答有关springboot版本修改的相关问题,此外,我们还将为您介绍
此处将为大家介绍关于为什么从Spring Boot版本2.1.4更改为2.1.5会给出未知的配置Maven错误?的详细内容,并且为您解答有关springboot版本修改的相关问题,此外,我们还将为您介绍关于"通过 Maven 在 SpringBoot 中配置活动配置文件" - Configure active profile in SpringBoot via Maven、idea:spring initializr 无 web 勾选,maven 方式搭建 springboot 项目。jdk7 创建 springboot 项目的版本不兼容问题。、IntelliJ IDEA(的springboot项目)环境准备(配置maven和jdk)、java Spring Boot的Maven插件Spring Boot Maven plugin详解的有用信息。
本文目录一览:- 为什么从Spring Boot版本2.1.4更改为2.1.5会给出未知的配置Maven错误?(springboot版本修改)
- "通过 Maven 在 SpringBoot 中配置活动配置文件" - Configure active profile in SpringBoot via Maven
- idea:spring initializr 无 web 勾选,maven 方式搭建 springboot 项目。jdk7 创建 springboot 项目的版本不兼容问题。
- IntelliJ IDEA(的springboot项目)环境准备(配置maven和jdk)
- java Spring Boot的Maven插件Spring Boot Maven plugin详解
为什么从Spring Boot版本2.1.4更改为2.1.5会给出未知的配置Maven错误?(springboot版本修改)
我已经安装了Eclipse(实际上是Spring Tool Suite)。它与Maven一起提供。我已经创建了Spring boot
starter项目。Maven正在下载所有依赖项,并且一切正常。
最近,我创建了一个新项目。这次,我注意到pom.xml中出现错误,并且问题窗口(在STS中)显示以下内容:
Description Resource Path Location TypeUnknown pom.xml /TestSessionAttribute line 1 Maven Configuration Problem
我注意到spring boot版本是2.1.5(之前是2.1.4)。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --></parent>
我继续进行了项目的更新(Maven>更新项目),并选中了“强制更新快照/发布”。这不能解决问题。我确实看到了
spring-boot-2.1.5.RELEASE.jar
在m2存储库中。
我回过头来,将版本更改为2.1.4,然后执行了Maven>更新项目,错误消失了。
为什么在版本2.1.5时出现Maven错误?
答案1
小编典典根据此链接,可以通过将maven-jar-
plugin降级到3.1.1(从3.1.2)来解决此问题。我可以确认该修复程序适用于我自己的项目。
将以下条目添加到pom中以解决该问题。
<properties> <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version></properties>
eclipse的官方错误条目也存在。
"通过 Maven 在 SpringBoot 中配置活动配置文件" - Configure active profile in SpringBoot via Maven
问题:
"I''m trying to set an active profile in Spring Boot application using Maven 3.<\/i> 我正在尝试使用 Maven 3 在 Spring Boot 应用程序中设置活动配置文件。<\/b>
In my pom.xml I set default active profile<\/strong> and property spring.profiles.active<\/strong> to development<\/strong> :<\/i> 在我的 pom.xml 中,我将默认活动配置文件 <\/strong> 和属性 spring.profiles.active 设置 <\/strong> 为 development<\/strong> :<\/b><\/p>
<profiles>
<profile>
<id>development</id>
<properties>
<spring.profiles.active>development</spring.profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
解决方案:
参考: https://stackoom.com/en/question/2rrnYidea:spring initializr 无 web 勾选,maven 方式搭建 springboot 项目。jdk7 创建 springboot 项目的版本不兼容问题。
一、idea 使用 spring initializr 不选择 web 搭建 springboot 项目
1.file => new => project
2. 直接 next 到 finish 结束。
3. 完成后创建 controller 用例测试
4.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 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.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cc.ash</groupId>
<artifactId>boot-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.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>
</dependency>
<!-- 手动添加web依赖,@restController @requestMapping注解等 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
5.application.properties
#端口号修改。默认8080
server.port=
6.springboot 入口启动类
package cc.ash.bootdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@SpringBootApplication
@Controller
public class BootDemoApplication {
@RequestMapping("/boot")
@ResponseBody
public String bootTest() {
return "hello springboot";
}
public static void main(String[] args) {
SpringApplication.run(BootDemoApplication.class, args);
}
}
7. 新建包下 controller 测试类
package cc.ash.bootdemo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping(name="springboot test", value = "/test")
public String test() {
return "booted";
}
}
8. 运行结果
新建包下 controller 测试类:访问页面
springboot 启动类中访问 404。改 requestMapping、rerun,做了很多操作到怀疑人生。重启 idea,世界终于正常了。
能正常访问的结果如下
二、maven 搭建 springboot 项目
1.jdk7 的情况下
2.maven 搭建
创建完成后的项目结构和 pom 文件。一个字就是干净
3. 手动添加 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cc.ash</groupId>
<artifactId>boot-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<!-- =================jdk1.7与springboot版本不兼容======================= -->
<!--<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.myproject.Application</start-class>
</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>
</dependency>
<!-- 手动添加web依赖,@restController @requestMapping注解等 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
maven 导入依赖(未选择自动导入的情况下)。
4. 编写测试用例代码
1). 测试 controller:
TestController
package cc.ash.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping(name="maven手动创建springboot",value={"/manual", "mvnManual"})
@ResponseBody
public String test() {
return "maven manual";
}
}
2. 启动入口:
DemoApplication
package cc.ash;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
3. 完成后代码结构
5. 访问测试
6.jdk1.7 错误留存
不兼容问题
https://blog.csdn.net/wj197927/article/details/79557017
https://www.jianshu.com/p/95d8a0cf0244
idea 日志记录(非控制台日志,控制台日志如上)
7.springboot 项目结构导致 controller 访问 404 的问题
自建的所有需要扫描注解的类,必须与启动类的包平级或者在其之下。如启动类在包【aa.bb】,其他需要扫描的类必须在【aa.bb】中或【aa.bb】之下的包里。
参考链接:
详细说明的:https://www.cnblogs.com/remember-me/p/10091126.html
直接上解决方法的:https://blog.csdn.net/dong__CSDN/article/details/85342180
IntelliJ IDEA(的springboot项目)环境准备(配置maven和jdk)
1.配置maven .使用自己电脑上装的maven版本,而非默认的。(方法一)
(1)选择configure--Settings
(2)搜索maven,配置3.6.2版本的maven.注意:将maven下载解压后,拷贝一份settings.xml到C://user/asus/m2的路径下(此步骤非常关键)然后再修改setting.xml.的mirror。User settings file的地址即C://Users\asus\.m2\settings.xml。.总之,idea中User settings file路径与电脑上的路径保持一致。idea中Local repository的路径与settings.xml中配置的<repository>保持一致。
(3)导入源码
方法(二)
(1)file--settings
2.配置jdk1.8,点击File--Project Stucture.
java Spring Boot的Maven插件Spring Boot Maven plugin详解
Spring Boot的Maven插件(Spring Boot Maven plugin)能够以Maven的方式为应用提供Spring Boot的支持,即为Spring Boot应用提供了执行Maven操作的可能。
Spring Boot Maven plugin能够将Spring Boot应用打包为可执行的jar或war文件,然后以通常的方式运行Spring Boot应用。
1. Spring Boot Maven plugin的5个Goals
spring-boot:repackage,默认goal。在mvn package之后,再次打包可执行的jar/war,同时保留mvn package生成的jar/war为.origin
spring-boot:run,运行Spring Boot应用
spring-boot:start,在mvn integration-test阶段,进行Spring Boot应用生命周期的管理
spring-boot:stop,在mvn integration-test阶段,进行Spring Boot应用生命周期的管理
spring-boot:build-info,生成Actuator使用的构建信息文件build-info.properties
2. 配置pom.xml文件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.4.RELEASE</version>
</plugin>
</plugins>
</build>
3.mvn package spring-boot:repackage说明
Spring Boot Maven plugin的最主要goal就是repackage,其在Maven的package生命周期阶段,能够将mvn package生成的软件包,再次打包为可执行的软件包,并将mvn package生成的软件包重命名为*.original。
基于上述配置,对一个生成Jar软件包的项目执行如下命令。
mvn package spring-boot:repackage
可以看到生成的两个jar文件,一个是*.jar,另一个是*.jar.original。
在执行上述命令的过程中,Maven首先在package阶段打包生成*.jar文件;然后执行spring-boot:repackage重新打包,查找Manifest文件中配置的Main-Class属性,如下所示:
Manifest-Version: 1.0
Implementation-Title: gs-consuming-rest
Implementation-Version: 0.1.0
Archiver-Version: Plexus Archiver
Built-By: exihaxi
Implementation-vendor-Id: org.springframework
Spring-Boot-Version: 1.5.3.RELEASE
Implementation-vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.ericsson.ramltest.MyApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.0
Build-Jdk: 1.8.0_131
注意,其中的Main-Class属性值为org.springframework.boot.loader.JarLauncher;
Start-Class属性值为com.ericsson.ramltest.MyApplication。
其中com.ericsson.ramltest.MyApplication类中定义了main()方法,是程序的入口。
通常,Spring Boot Maven plugin会在打包过程中自动为Manifest文件设置Main-Class属性,事实上该属性究竟作用几何,还可以受Spring Boot Maven plugin的配置属性layout控制的,示例如下。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.4.RELEASE</version>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
注意,这里的layout属性值为ZIP。
layout属性的值可以如下:
JAR,即通常的可执行jar
Main-Class: org.springframework.boot.loader.JarLauncher
WAR,即通常的可执行war,需要的servlet容器依赖位于WEB-INF/lib-provided
Main-Class: org.springframework.boot.loader.warLauncher
ZIP,即DIR,类似于JAR
Main-Class: org.springframework.boot.loader.PropertiesLauncher
MODULE,将所有的依赖库打包(scope为provided的除外),但是不打包Spring Boot的任何Launcher。
NONE,将所有的依赖库打包,但是不打包Spring Boot的任何Launcher。
4.integration-test阶段中的Spring Boot Maven plugin的start/stop
<properties>
<it.skip>false</it.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>${it.skip}</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.4.RELEASE</version>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<skip>${it.skip}</skip>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
<configuration>
<skip>${it.skip}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
注意,it.skip变量用作是否跳过integration-test的标志位。
maven-failsafe-plugin用作integration-test的主要执行目标。
spring-boot-maven-plugin用以为integration-test提供支持。
执行integration-test的Maven命令如下:
mvn verify
或者
mvn verify -Dit.skip=false
今天的关于为什么从Spring Boot版本2.1.4更改为2.1.5会给出未知的配置Maven错误?和springboot版本修改的分享已经结束,谢谢您的关注,如果想了解更多关于"通过 Maven 在 SpringBoot 中配置活动配置文件" - Configure active profile in SpringBoot via Maven、idea:spring initializr 无 web 勾选,maven 方式搭建 springboot 项目。jdk7 创建 springboot 项目的版本不兼容问题。、IntelliJ IDEA(的springboot项目)环境准备(配置maven和jdk)、java Spring Boot的Maven插件Spring Boot Maven plugin详解的相关知识,请在本站进行查询。
本文标签: