SpringBoot------新建一个项目
Posted 玉天恒
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot------新建一个项目相关的知识,希望对你有一定的参考价值。
1.新建一个Maven Project
2.选择项目路劲
3.选择Web App
4.添加项目名称
5.右击“Properties”-》“Java Build Path”-》“Source”,发现缺少两个路径
解决方法:现将原来两个缺少的路径删除,再重新添加,再调整下位置
6.打开pom.xml文件,添加依赖包,保存
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.itsource</groupId> <artifactId>springboot-shop</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>springboot-shop Maven Webapp</name> <url>http://maven.apache.org</url> <!-- 如果添加了Parent,则dependency中可以不加入version,会自动匹配parent的版本 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.15</version> </dependency> </dependencies> <build> <finalName>myshop</finalName> <!-- 热部署插件 --> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
7.编写HelloController.java
package myshop.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @RestController = @Controller + @RequestBody * */ @RestController public class HelloController { /** * 建立请求映射 * */ @RequestMapping public String hello() { return "hello"; } }
8.编写启动类
package myshop.controller; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class App { public static void main(String[] args) { // TODO Auto-generated method stub SpringApplication.run(App.class, args); } }
9.右键项目-》“Debug As”-》“Java Application”,启动项目
如图所示,则表示启动成功
10.打开链接:http://localhost:8080/hello
11.恭喜你,项目Spring Boot项目成功啦~~~
以上是关于SpringBoot------新建一个项目的主要内容,如果未能解决你的问题,请参考以下文章
springboot配置文件application-dev.properties,application-prod.properties,application-test.properties(代码片
3.springboot:springboot配置文件(配置文件YAML属性文件值注入<@Value@ConfigurationProperties@PropertySource,@Im(代码片
3springboot:springboot配置文件(配置文件YAML属性文件值注入<@Value@ConfigurationProperties@PropertySource,@Imp(代码片