spring cloud-学习之路(一):搭建一个简单的Springboot项目

来源:互联网 发布:nginx 不允许加参数 编辑:程序博客网 时间:2024/06/04 21:56

文件目录(注意:Springboot启动类App.class必须放在最外层)


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.crazy_qu.sc</groupId>    <artifactId>springboot-helloWorld</artifactId>    <version>1.0-SNAPSHOT</version>    <packaging>jar</packaging>    <!-- 启用springboot项目必须引入spring-boot-starter-parent依赖,下面这个依赖中已经集成了 -->    <parent>        <groupId>org.springframework.cloud</groupId>        <artifactId>spring-cloud-starter-parent</artifactId>        <version>Brixton.RELEASE</version>        <relativePath />    </parent>    <dependencies>        <!--web应用基本环境配置 -->        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>    </dependencies>    <build>        <plugins>            <!-- 要部署运行spring boot应用,首选要打包spring boot应用,你在pom文件中看到的spring-boot-maven-plugin插件就是打包spring boot应用的。 -->            <!-- D:\springboot-helloWorld>mvn package 打包过后就可以进入target目录使用java原生命令执行这个应用了。                D:\springboot-helloWorld\target>java -jar cloud-simple-helloword-0.0.1.jar -(执行的时候是两个横杠)-server.port=8081                如此,你就看到一个基于jar包的web应用启动了。 -->            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>        </plugins>    </build></project>

App.class

package com.crazy_qu.hello;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.ComponentScan;/** * Created by crazy on 2017/11/29. */@SpringBootApplication@ComponentScan(basePackages = {"com.crazy_qu.hello.controller"})public class App {    public static void main(String[] args){        SpringApplication.run(App.class, args);    }}

AppController.class

package com.crazy_qu.hello.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;/** * Created by crazy on 2017/11/29. */@Controllerpublic class AppController {    @RequestMapping("/")    @ResponseBody    public String getResult(){        return "hello world";    }}

代码写好之后,直接在浏览器中访问:http://localhost:8080/


一个简单的springboot项目就搭建完成了


阅读全文
0 0
原创粉丝点击