【SpringSecurity+OAuth2+JWT入门到实战】2.启动项目

编程

新建Controller



HelloController

package com.spring.security.controller;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

@RestController

public class HelloController {

@GetMapping("hello")

public String hello() {

return "hello spring security";

}

}

 

启动项目

在SpringSecurityDemoApplication运行main启动demo项目

报错: 由于我们引入了MySQL的依赖但是没有配置数据库连接

Description:

Failed to configure a DataSource: "url" attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:

If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.

If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

 

配置数据库连接

application.yml

spring:

datasource:

driver-class-name: com.mysql.jdbc.Driver

url: jdbc:mysql://127.0.0.1/auto_test?useUnicode=yes&characterEncoding=UTF-8&useSSL=false

username: root

password: 123456

 

再次启动项目:启动成功并输出security密码

 

访问:http://127.0.0.1:8080/login    默认security会拦截全部访问连接,后期说怎么过拦截

security默认用户名为:user   密码为:控制台输出密码,登录:

以上是 【SpringSecurity+OAuth2+JWT入门到实战】2.启动项目 的全部内容, 来源链接: utcz.com/z/513986.html

回到顶部