3.security之Hello World

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lovelovelovelovelo/article/details/88353815

security-demo增加配置文件
application.properties

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mysecurity?useUnicode=yes&charaterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=123456

spring.session.store-type=none

DemoApplication

package com.csdn;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

	public static void main(String[] args) {
			SpringApplication.run(DemoApplication.class, args);
	}
	
	@RequestMapping("/hello")
	public String hello(){
		return "hello world";
	}
}

启动DemoApplication
在这里插入图片描述
访问localhost:8080/hello
需要进行认证
输入用户名:user
密码如上面的截图
在这里插入图片描述

若要取消认证,配置文件中加入
security.basic.enabled=false

猜你喜欢

转载自blog.csdn.net/lovelovelovelovelo/article/details/88353815