在IntelliJ IDEA下搭建基于Maven的spring boot框架
来源:互联网 发布:安卓sd卡数据恢复软件 编辑:程序博客网 时间:2024/06/05 14:13
基础环境:JDK 1.8 、IntelliJ IDEA 2017.2.5
因为spring boot 框架内置有Tomcat,所以这里就不用另外单独配置Tomcat环境
接下来通过具体的步骤来讲解在IntelliJ IDEA下搭建Maven+spring boot项目。
步骤一:首先在IDEA中新建一个普通的Maven项目,具体如下图所示:
通过上图的几步操作,一个基本的Maven项目就已经搭建完成了,接下来就可以开始搭建spring boot框架以及相关的配置文件。
步骤二:在配置文件pom.xml中注入属性及依赖项
初始化的pom.xml文件内容:
配置后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> <groupId>com.demo</groupId> <artifactId>demo</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>demo</name> <description>Demo project for spring boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </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>
步骤三:更新项目依赖的jar包,具体操作如下:
步骤四:在所建项目目录下新建若干包和类,具体如下图所示:
其中com.sample下的两个文件夹和一个Java类,controller、service,分别用来存储控制层和服务层的内容(后续还会有Dao层目录),DemoApplication类是项目运行主函数,resources下面的有两个文件夹和一个属性文件,其中static是存储一些静态文件例如css、js等,template是存储模板文件的而application.properties则是spring boot的配置文件。
步骤五:在所建Java类中写入以下代码,并测试项目是否能成功运行。
DemoApplication.java
import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }}
indexController.java
import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controllerpublic class IndexController { @RequestMapping(path={"/index","/"}) @ResponseBody public String index(){ return "Hello World"; }}
运行成功如下图所示:
至此一个基本的基于Maven的spring boot框架就搭建完成了。
阅读全文
0 0
- 在IntelliJ IDEA下搭建基于Maven的spring boot框架
- 【Spring】基于IntelliJ IDEA搭建Maven
- 【Spring】基于IntelliJ IDEA搭建Maven
- 在IDEA下 spring+springMVC+hibernate+maven框架搭建
- 使用intellij idea搭建MAVEN+SSM(Spring+SpringMVC+MyBatis)框架
- 使用intellij idea搭建MAVEN+SSM(Spring+SpringMVC+MyBatis)框架
- IntelliJ IDEA搭建Spring Boot的小Demo
- Intellij IDEA搭建maven+注解SpringMVC框架
- SpringBoot + MyBatis + MySQL + Maven在Intellij IDEA下开发环境的搭建
- Intellij IDEA + Spring MVC + Maven 环境搭建
- intellij IDEA 搭建基于 Gradle 的 Spring 项目
- spring boot maven 框架搭建
- intellij idea下使用Maven搭建SpringMVC
- intellij idea下使用Maven搭建SpringMVC
- intellij idea下使用Maven搭建SpringMVC
- IntelliJ IDEA + Spring Boot + Mybatis的整合
- idea中搭建基于maven的ssm整合框架
- intellij idea + bitbucket + maven + spring-boot配置记录
- 常用的Oracle的doc命令
- JAVA面试题整理之—基础篇第一部
- poj 2287 田忌赛马
- 剑指Offer------字符串的排列(全排列)
- ACM ICPC 2017 Warmup Contest 1 (NCPC 2016)
- 在IntelliJ IDEA下搭建基于Maven的spring boot框架
- 215[Medium]:Kth Largest Element in an Array
- Gemfire命令集
- JavaScript 数组对象深拷贝与浅拷贝
- JavaWeb笔记(1)
- Spring报错:org.springframework.beans.factory.NoUniqueBeanDefinitionException
- B-number (数位DP)
- hdu1754
- Tensorflow实战Google-第四章深层神经网络知识点