温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SpringBoot idea下的环境怎么搭建

发布时间:2021-11-24 14:00:18 来源:亿速云 阅读:271 作者:小新 栏目:大数据

这篇文章主要介绍SpringBoot  idea下的环境怎么搭建,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1.Spring Boot简介
wiki上的介绍:

Spring Boot是Spring的常规配置解决方案,用于创建可以“运行”的独立的,生产级的基于Spring的应用程序。[22]它预先配置了Spring对Spring平台和第三方库的最佳配置和使用的“见解视图”,因此您可以尽量少开始。大多数Spring Boot应用程序只需要很少的Spring配置。特征:

创建独立的Spring应用程序
直接嵌入Tomcat或Jetty(无需部署WAR文件)
提供自以为是的“初学者” 项目对象模型(POM)以简化您的Maven配置
尽可能自动配置Spring
提供生产就绪功能,例如指标,运行状况检查和外部化配置
绝对没有代码生成,也不需要XML配置

  1. 创建项目
    新建一个maven项目:打开IDEA,选择File->New->Project如下图所示:

小编带您进入SpringBoot (1) idea下的环境搭建及demo
找到Maven项目,如下图所示:

小编带您进入SpringBoot (1) idea下的环境搭建及demo
然后,填写各项,

小编带您进入SpringBoot (1) idea下的环境搭建及demo
3.pom.xml配置
参考spring官网的例子:https://spring.io/guides/gs/maven/#initial

如下:?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>
<groupId>org.springframework</groupId>
<artifactId>myspringboot</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.demo.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
除了可选<packaging>元素之外,这是构建Java项目所必需的最简单的pom.xml文件。它包括项目配置的以下详细信息:

<modelVersion>。POM模型版本(总是4.0.0)。
<groupId>。项目所属的组或组织。通常表示为反向域名。
<artifactId>。要赋予项目库工件的名称(例如,其JAR或WAR文件的名称)。
<version>。正在构建的项目的版本。
<packaging> - 如何打包项目。对于JAR文件打包,默认为“jar”。使用“war”进行WAR文件打包。
4.添加启动类
在 src/main/java 路径下创建一个包,我以com.demo命名。包下面新建一个java类,命名为HelloWorld作为启动类。

HelloWorld.java代码:

package com.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
br/>@Controller<br/public class helloController {@RequestMapping("/hello")<br/" rel="nofollow">br/>@RequestMapping("/hello")<br/@ResponseBody
public String hello(){
return "hello spring boot";
}
}
6.运行
这样一个简单的demo就完成了。直接在启动类中运行main方法,即可启动项目;因为sping boot 已经内置了tomcat

小编带您进入SpringBoot (1) idea下的环境搭建及demo
可以看到tomcat已在8080端口运行,在浏览器地址栏输入:http://localhost:8080/hello

以上是“SpringBoot  idea下的环境怎么搭建”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI