博客
关于我
《springboot学习笔记 01》--打印helloworld
阅读量:231 次
发布时间:2019-02-28

本文共 1653 字,大约阅读时间需要 5 分钟。

Spring Boot项目基础搭建指南

一、项目基础搭建

  • 新建Spring Boot Maven项目

    创建一个普通的Maven项目,路径为C:\work\workspace\a-springboot-test

  • 配置POM文件

    在项目根目录下找到pom.xml文件,添加必要的Spring Boot依赖。以下是推荐的配置:

    org.springframework.boot
    spring-boot-starter-parent
    1.4.4.RELEASE
    org.springframework.boot
    spring-boot-starter-web
  • 创建测试类并运行

    新建一个测试类Demo.java,内容如下:

    import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class Demo {    public static void main(String[] args) {        SpringApplication.run(Demo.class, args);    }}
  • 运行此类,启动Spring Boot应用,无需处理端口冲突即可正常运行。

    二、通过浏览器访问应用

  • 配置Spring MVC组件扫描

    src/main/resources/app.xml中添加以下配置:

  • 配置Web.xml文件

    src/main/resources/web.xml中添加以下配置:

    springboot-test
    org.springframework.web.servlet.DispatcherServlet
    contextConfigLocation
    classpath:app.xml
    springboot-test
    /
  • 编写Hello World控制器

    创建HelloWorldController类,内容如下:

    @RestController@RequestMapping("/api")public class HelloWorldController {    @GetMapping("/hello")    public String sayHello() {        return "Hello World!";    }}
  • 启动测试并验证

    使用IDE运行Demo.java,访问http://localhost:8080/api/hello,查看是否返回"Hello World!"。

  • 注意事项

    • 如果默认端口8080已占用,可以通过修改application.properties文件设置端口:

      server.port=8081
    • 配置完成后,项目即可通过浏览器访问,测试功能正常运行即可确认配置成功。

    通过以上步骤,您可以成功搭建一个Spring Boot项目并进行基本的应用开发。如果需要进一步优化或扩展,请参考Spring Boot官方文档或相关技术博客。

    转载地址:http://dwip.baihongyu.com/

    你可能感兴趣的文章
    Nginx下配置codeigniter框架方法
    查看>>
    Nginx之二:nginx.conf简单配置(参数详解)
    查看>>
    Nginx代理websocket配置(解决websocket异常断开连接tcp连接不断问题)
    查看>>
    Nginx代理初探
    查看>>
    Nginx代理外网映射
    查看>>
    Nginx代理模式下 log-format 获取客户端真实IP
    查看>>
    Nginx代理静态资源(gis瓦片图片)实现非固定ip的url适配网络环境映射ip下的资源请求解决方案
    查看>>
    Nginx反向代理与正向代理配置
    查看>>
    Nginx多域名,多证书,多服务配置,实用版
    查看>>
    nginx异常:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf
    查看>>
    nginx总结及使用Docker创建nginx教程
    查看>>
    nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:128
    查看>>
    nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in usrlocalnginxconfnginx.conf128
    查看>>
    nginx最最最详细教程来了
    查看>>
    Nginx服务器上安装SSL证书
    查看>>
    Nginx服务器的安装
    查看>>
    Nginx模块 ngx_http_limit_conn_module 限制连接数
    查看>>
    nginx添加模块与https支持
    查看>>
    Nginx用户认证
    查看>>
    Nginx的location匹配规则的关键问题详解
    查看>>