Spring cloud oauth2 研究第N天

来源:互联网 发布:怎么用python画图 编辑:程序博客网 时间:2024/05/22 14:35

抱歉,原先没有发表,是因为一直在参考 

http://blog.csdn.net/j754379117/article/details/70176974

http://blog.csdn.net/j754379117/article/details/70175198

https://spring.io/guides/tutorials/spring-boot-oauth2/


现在配置好,运行报

PreparedStatementCallback; bad SQL grammar [select username,password,enabled from users where username = ?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'users' doesn't exist


不难看出在Spring Security源码中导数据库中查询用户名密码,及其用户对应的权限是其固定写在代码里面的,这就是为什么网上的一些小的demo中数据库为什么这么创建的原因。下面给出MySQL创建这两张的SQL语句及其插入数据的相关语句:

Sql代码  收藏代码
  1. create table users(  
  2. username varchar(50) not null primary key,  
  3. password varchar(50) not null,  
  4. enabled boolean not null  
  5. );  
  6. create table authorities (  
  7. username varchar(50) not null,  
  8. authority varchar(50) not null,  
  9. constraint fk_authorities_users foreign key(username) references users(username)  
  10. );  
  11. create unique index ix_auth_username on authorities (username,authority);  
  12.   
  13. insert into users(username,password,enabled) values('admin','admin',true);  
  14. insert into users(username,password,enabled) values('user','user',true);  
  15.   
  16. insert into authorities(username,authority) values('admin','ROLE_ADMIN');  
  17. insert into authorities(username,authority) values('admin','ROLE_USER');  
  18. insert into authorities(username,authority) values('user','ROLE_USER'); 

原创粉丝点击