首先new一个project
点击next继续,
next继续
next继续,
点击finish,创建完成
点击运行,出现如下结果:
这是因为缺少数据库的参数配置导致,继续添加数据库参数配置。
application.properties 改为application.yml,可以不改,视个人喜好而定。
spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/boot_backend?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false username: root1 password: root1 druid: initialSize: 5 minIdle: 5 maxActive: 20 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: true testOnReturn: false poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 filters: stat,wall connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 stat-view-servlet: allow: 127.0.0.1
参数错误没关系,只要有配置,springboot就可以读取到配置,不会报错。
再次启动服务,成功!
创建类TestController.java
package com.liuxy.nes3.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController public class TestController { @RequestMapping(value = "/test",method = RequestMethod.GET) public String hello() { return "test the new spring boot!"; } }
再次启动服务,浏览器输入http://localhost:8080/test