springboot和springcloud的区别(springboot)
1、创建一个Maven工程:
2、导入SpringBoot相关的攀侧救依赖包:
3、<parent>
4、 <groupId>org.springframework.boot</groupId>
5、 <artifactId>spring-boot-starter-parent</artifactId>
6、 <version>2.0.0.RELEASE</version>
7、 </parent>
8、 <dependencies>
9、 <dependency>
10、 <groupId>org.springframework.boot</groupId>
11、 <artifactId>spring-boot-starter-web</artifactId>
12、 搁距 </dependency>
13、 </dependencies>
14、编写一个主程序,启动Spring Boot应用。
15、package com.gwolf;
16、import org.springframework.boot.SpringApplication;
17、import org.springframework.boot.autoconfigure.SpringBootApplication;
18、import org.springframework.web.bind.annotation.RequestMapping;
19、import org.springframework.web.bind.annotation.ResponseBody;
20、@SpringBootApplication
21、public class SpringHelloMainApplication {
22、 public static void main(String[] args) throws Exception {
23、 SpringApplication.run(SpringHelloMainApplication.class, args);
24、 }
25、}
26、编写相关的Controller、Service。
27、package com.gwolf.controller;
28、import org.springframework.stereotype.Controller;
29、import org.springframework.web.bind.annotation.RequestMapping;
30、import org.springframework.web.bind.annotation.ResponseBody;
31、@Controller
32、public class HelloController {
33、 @ResponseBody
34、 @RequestMapping("/hello")
35、 public String hello() {
36、 return "hello World!";
37、 }
38、}
39、启动主程序的main方法启动应用。
40、在浏览器中访问地址:http://localhost:8080/hello
41、springboot打包部署也是鉴栗相当简单,只需要导入一个插件。将这个应用打成一个jar包可以直接使用java -jar命令进行执行。
42、<build>
43、 <plugins>
44、 <plugin>
45、 <groupId>org.springframework.boot</groupId>
46、 <artifactId>spring-boot-maven-plugin</artifactId>
47、 </plugin>
48、 </plugins>
49、 </build>
以上就是springboot这篇文章的一些介绍,希望对大家有所帮助。