SpringBoot 搭建
2024-08-31 01:24:49
1、使用Eclipse 建立Maven项目(webapp OR quickstart)
2、配置Maven,如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath/>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
3、建立启动Application
package demo.web.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; @SpringBootApplication
@ComponentScan(basePackages={"demo.web.*"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
} }
4、编辑Controller
package demo.web.controller;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@EnableAutoConfiguration
public class HelloController { @RequestMapping("/")
String home() {
System.out.println("ee");
return "Hello World!";
} @RequestMapping("/hello/{myName}")
String index(@PathVariable String myName) {
return "Hello "+myName+"!!!";
} }
5、通过application.properties对项目进行配置
server.port=9000
项目文件布局如下:
启动Application程序,即可访问网站。
最新文章
- IDEA设置代码大小以及菜单栏大小
- 《DSP using MATLAB》示例Example5.7
- service XXX does not support chkconfig
- Android常用控件
- do some projects in macine learning using python
- 传智168期JavaEE就业班 day04-dom
- mysql server has gone away 与max_allowed_packed
- poj3020
- Consistent Hashing原理与实现
- TabHost 两种使用方法 直接让一个Activity 继承TabActivity 和 利用findViwById()方法取得TagHost组件
- 与Scheme共舞
- Python 2.7 学习笔记 基本语法和函数定义
- oracle报表开发方案
- Zabbix实战-简易教程--通过公众平台企业号发送短信
- RTMPdump(libRTMP) 源代码分析 9: 接收消息(Message)(接收视音频数据)
- 新系统添加sshkey/pexpect基本使用
- C# 解析html中筛选class的问题
- Net 4.5 WebSocket 在 Windows 7, Windows 8 and Server 2012上的比较以及问题
- 关于Mysql表InnoDB下插入速度慢的解决方案
- JavaSE 类继承中函数重写