如何在intellij中运行Spring Boot应用程序? [英] How to run a spring boot app in intellij?

查看:147
本文介绍了如何在intellij中运行Spring Boot应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以intellij的想法运行演示春季启动应用程序,但是我遇到了错误:

I want to run a demo spring boot app in intellij idea but i have the error:

Error:(3, 32) java: package org.springframework.boot does not exist

我的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 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>1.5.21.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>helloworld</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>helloworld</name>
    <description>Hello World project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.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>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

推荐答案

请确保打开pom.xml而非文件夹. IntelliJ将询问您是否要导入为项目.对这个问题回答是. 您始终可以右键单击pom.xml,然后选择Maven-> Reimport,它将自动为您创建类路径.

Be sure to open the pom.xml and not the folder. IntelliJ will ask if you want to import as a project. Answer yes to this question. You can always right-click on the pom.xml and choose Maven->Reimport which will do the classpath for you automatically.

然后从树中转到主类,然后右键单击并选择运行".那应该在您的运行配置中创建一个临时配置.

Then you go to the main class from the tree and right-click and choose Run. That should create a temporary configuration in your run configurations.

其余的您可以在这里找到:

The rest you can find here:

https://www.jetbrains.com/help/idea/running -applications.html

如果要作为Maven项目运行,请执行以下操作:

If you want to run as a maven project, go with this:

https://www.jetbrains.com/help /idea/work-with-maven-goals.html

如果要以Java jar从终端运行,则在构建spring-boot-jar时,按CTRL + TAB + T(以激活终端)并输入终端: java -jar target/yourjar.jar

If you want to run from terminal as java jar, when you have built your spring-boot-jar press CTRL+TAB+T (to activate terminal) and type in the terminal: java -jar target/yourjar.jar

这篇关于如何在intellij中运行Spring Boot应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆