无法 运行 Spring 在 IntelliJ 上使用 2.2.1.BUILD-SNAPSHOT 初始化
Unable to run Spring Initializr using 2.2.1.BUILD-SNAPSHOT on IntelliJ
试图在我的 j2ee 上刷机,所以下载了一个 Spring initializr 压缩文件夹并导入到 IntelliJ 中。
我在尝试 运行 作为 Java 应用程序时遇到错误。
2019-11-04 12:50:35.702 INFO 5900 --- [ main] com.example.spring.demo.DemoApplication : Starting DemoApplication on DESKTOP-OPAMEU4 with PID 5900 (C:\JavaWS\demo\demo\target\classes started by hemis in C:\JavaWS\demo\demo)
2019-11-04 12:50:35.705 INFO 5900 --- [ main] com.example.spring.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-11-04 12:50:36.413 INFO 5900 --- [ main] com.example.spring.demo.DemoApplication : Started DemoApplication in 1.24 seconds (JVM running for 2.4)
Process finished with exit code 0
下面是我的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.1.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.spring</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>13.0.1</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
有什么线索吗?
鉴于您的项目只是从 spring 初始化程序生成的,它实际上还没有做任何事情,您必须添加一些功能才能使其不立即退出。
如果您希望它以网络应用程序的形式启动,则必须添加对 spring-boot-starter-web
.
的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
如果您更喜欢 tomcat
作为您的容器,您可以使用上述依赖项,但如果您更喜欢其他东西 - 例如 jetty
,您将不得不排除 tomcat
来自 spring-boot-starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
然后开始时你会得到接近这个的东西 运行 DemoApplication
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.1.BUILD-SNAPSHOT)
2019-11-04 19:38:57.796 INFO 11674 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on hostname with PID 11674 (/tmp/demo/target/classes started by user in /tmp/demo)
2019-11-04 19:38:57.800 INFO 11674 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-11-04 19:38:58.446 INFO 11674 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-11-04 19:38:58.451 INFO 11674 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-11-04 19:38:58.451 INFO 11674 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-11-04 19:38:58.487 INFO 11674 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-04 19:38:58.487 INFO 11674 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 641 ms
2019-11-04 19:38:58.583 INFO 11674 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-11-04 19:38:58.690 INFO 11674 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-11-04 19:38:58.692 INFO 11674 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.148 seconds (JVM running for 1.714)
试图在我的 j2ee 上刷机,所以下载了一个 Spring initializr 压缩文件夹并导入到 IntelliJ 中。
我在尝试 运行 作为 Java 应用程序时遇到错误。
2019-11-04 12:50:35.702 INFO 5900 --- [ main] com.example.spring.demo.DemoApplication : Starting DemoApplication on DESKTOP-OPAMEU4 with PID 5900 (C:\JavaWS\demo\demo\target\classes started by hemis in C:\JavaWS\demo\demo)
2019-11-04 12:50:35.705 INFO 5900 --- [ main] com.example.spring.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-11-04 12:50:36.413 INFO 5900 --- [ main] com.example.spring.demo.DemoApplication : Started DemoApplication in 1.24 seconds (JVM running for 2.4)
Process finished with exit code 0
下面是我的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.1.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.spring</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>13.0.1</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
有什么线索吗?
鉴于您的项目只是从 spring 初始化程序生成的,它实际上还没有做任何事情,您必须添加一些功能才能使其不立即退出。
如果您希望它以网络应用程序的形式启动,则必须添加对 spring-boot-starter-web
.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
如果您更喜欢 tomcat
作为您的容器,您可以使用上述依赖项,但如果您更喜欢其他东西 - 例如 jetty
,您将不得不排除 tomcat
来自 spring-boot-starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
然后开始时你会得到接近这个的东西 运行 DemoApplication
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.1.BUILD-SNAPSHOT)
2019-11-04 19:38:57.796 INFO 11674 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on hostname with PID 11674 (/tmp/demo/target/classes started by user in /tmp/demo)
2019-11-04 19:38:57.800 INFO 11674 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-11-04 19:38:58.446 INFO 11674 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-11-04 19:38:58.451 INFO 11674 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-11-04 19:38:58.451 INFO 11674 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-11-04 19:38:58.487 INFO 11674 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-04 19:38:58.487 INFO 11674 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 641 ms
2019-11-04 19:38:58.583 INFO 11674 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-11-04 19:38:58.690 INFO 11674 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-11-04 19:38:58.692 INFO 11674 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.148 seconds (JVM running for 1.714)