引言
IDEA创建项目的位置问题
IDEA创建项目的启动器链接超时的问题
IDEA创建项目的pom.xml文件下载失败问题
1.IDEA创建项目的位置问题
左上角点击File ->new project ->Empty Project之后,会进入下面的页面,虽然IDEA的项目(project)相当于eclipse的workspace(工作空间),但我们也希望所有的项目在一个目录下。
我之前的项目位置不是在D:\idea下,是直接在D盘下,这让我十分苦恼,直接修改项目名后,位置也不会发生变化;解决办法是:1.在D盘下新建idea目录,然后再idea下新建untitled目录 2.再IDEA创建的项目名和项目的位置与目录保持一致
虽然原因未知,但之后所有新建的project都在D盘的idea目录下,原因我猜测是项目的创建位置默认选择再上一次项目的的同级目录中。
2.IDEA创建项目的启动器链接超时的问题
在Spring Initalizr中采用默认的 Default:http://start.aliyun.com后,可能出现链接失败或超时的问题
我的是第一次创建成功,第二次创建失败,都用的是我的手机热点,原因未知;后来我再一个博客的评论中找到了好多人使用阿里云的评论,就使用了这个网址。
http://start.aliyun.com
3.IDEA创建项目的pom.xml文件下载失败问题
提示:我的用的是type是maven Project,之前使用grade Project下载了两三天都失败了。
需要修改的是pom.xml中的文件,问题主要有
1.现在的最新 spring-boot.version是:2.2.2.RELEASE,但阿里云的支持速度没有那么快,所以才用的是2.1.6.RELEASE
2.我在测试的时候,少了一个这个junit-jupiter-api的jar包,导致程序运行失败;并且没有连接数据库文件时要把@SpringBootApplication要改为@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
3.pom.xml中的spring-boot-maven-plugin下载异常,添加 version:2.1.6.RELEASE下载成功;打出的JAR包在命令行运行时,会出现没有主目录的错误,添加 goal:repackage
<!-- 将这个应用打包成一个可执行的jar包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
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>
<groupId>com.example</groupId>
<artifactId>springboot1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.1.6.RELEASE</spring-boot.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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</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>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 将这个应用打包成一个可执行的jar包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>