Spring Boot 无效授权规范异常:用户名或密码错误[28000-200]

yrdbyhpb  于 2023-01-13  发布在  Spring
关注(0)|答案(4)|浏览(293)

下面是错误消息。

2020-06-15 13:10:23.623 ERROR 37317 --- [nio-8887-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-200]
### The error may exist in tech/bootcamp/community/mapper/UserMapper.java (best guess)
### The error may involve tech.bootcamp.community.mapper.UserMapper.insert
### The error occurred while executing an update
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-200]] with root cause

org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-200]
at tech.bootcamp.community.controller.AuthorizeController.callback(AuthorizeController.java:52) ~[classes/:na]

@Autowired
private UserMapper userMapper;

它会说这一行导致了错误。

userMapper.insert(user);

那么用户名和密码到底是什么呢?

ttvkxqim

ttvkxqim1#

您可以在application.properties上设置:

spring.datasource.username=dbuser
spring.datasource.password=dbpass

如果未显式设置,则使用默认值“sa”和“"。

eimct9ow

eimct9ow2#

下面的方法对我也很有效。

spring.datasource.username=sa
spring.datasource.password=
polkgigr

polkgigr3#

运行Spring后,转到http://localhost:8080/h2-console/
使用应用程序属性中的相同配置JDBC URL: jdbc:h2:mem:testdb
connect with empty user namer and password if you not set like answer above from DEWA Kazuyuki - 出羽和之.
用户名:
密码:

ws51t4hk

ws51t4hk4#

如果我们不想使用默认用户名(sa)和密码(“”),则需要在www.example.com文件中定义用户名和密码application.properties示例:-

spring.datasource.username=mydb
spring.datasource.password=mypass

你可以使用任何用户名和任何密码,如果你想使用用户名而不是 sa,如果你使用 sa 作为用户名,那么你需要定义passwordf为空白

相关问题