idea实现第一个springboot程序
2021/5/19 20:59:31
本文主要是介绍idea实现第一个springboot程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.环境准备
- JDK:1.8
- Apache Maven: 3.6.1
- IntelliJ IDEA 2019.1.3 x64
- SpringBoot 1.5.9.RELEASE:1.5.9;
1.1、MAVEN设置:给maven 的settings.xml配置文件的profiles标签添加
<profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>
2.实现SpringBoot Helloworld 案例
浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串;
2.1、创建一个maven工程;(jar)
2.2、导入spring boot相关的依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
3、编写一个主程序;启动Spring Boot应用
package com.xdr; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /* @SpringBootApplication 来标注一个主程序 */ @SpringBootApplication public class HelloWorldApplication { public static void main(String[] args) { System.out.println("启动springboot程序"); SpringApplication.run(HelloWorldApplication.class, args); } }
4、编写相关的Controller、Service
package com.xdr.com.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class Controller { @RequestMapping("hello") public String sayHello(){ return "Hello SpringBoot"; } }
5、运行主程序测试
在resource下创建application.properties文件写入
server.port=8082
把端口号改为8082,以免跟8080冲突
访问项目
6、简化部署
<!-- 这个插件,可以将应用打包成一个可执行的jar包;--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
将这个应用打成jar包,直接使用java -jar xxx.jar(xxx表示jar包的名称)的命令进行执行;
在idea自带Maven打包中
刷新项目:
这篇关于idea实现第一个springboot程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-04TiDB 资源管控的对撞测试以及最佳实践架构
- 2024-07-03万字长文聊聊Web3的组成架构
- 2024-07-02springboot项目无法注册到nacos-icode9专业技术文章分享
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现