Intellij Idea简化了春季启动的开发,使其成为Java开发人员的最爱。 它的惯例与配置方法最小化了样板代码,从而使开发人员可以专注于业务逻辑。本教程演示了两种用于在Intellij Idea中创建和运行基本春季启动应用程序的方法。
>这种强大的IDE促进了具有必要依赖项的项目创建,并导入现有的Spring Boot项目。 在开始之前,请确保您有:
>步骤1:Intellij Ideas安装
>访问Intellij Idea网站:newProject
选择所需的依赖项(例如,春季Web)。
>步骤3:创建和配置Spring Boot Project
方法1:使用Spring Initializr
在Intellij Idea中打开下载的zip文件。
controller
在newProject -> src/main/java
软件包中创建一个类ExampleC
controller
>将以下代码添加到
ExampleC
>package org.example.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class ExampleC { @RequestMapping("/firstApp") @ResponseBody public String firstSpringApp(){ return "Welcome!"; } }
pom.xml
>标签中添加以下依赖项:<dependencies>
package org.example.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class ExampleC { @RequestMapping("/firstApp") @ResponseBody public String firstSpringApp(){ return "Welcome!"; } }
@SpringBootApplication
>添加
SpringApplication.run(Main.class, args);
main
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.5.3</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.5.3</version> </dependency> </dependencies>
ExampleC
步骤5:查看结果
>通过的浏览器访问该应用程序。您应该看到“欢迎!”。
http://localhost:8080/firstApp
以上是如何在Intellij中运行第一个春季启动应用程序?的详细内容。更多信息请关注PHP中文网其他相关文章!