文章目录
- 1.`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有关datasource`
- 2. `Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup`
- 3. `Error running 'SecurityTest.testPw': Failed to resolve org.junit.platform:junit-platform-launcher:1.5.2`
- 4. `There was an unexpected error (type=Not Found, status=404).No message available`
- 5. `Encoded password does not look like BCrypt`
- 6. @Autowired注解时发现有错误提示:`could not autowire,no beans of "XXX" type found`,但程序的编译和运行都正常
- 7. Reader r = new FileReader("userText.txt");系统找不到指定文件
- 8. `Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start`
- 9. `A component required a bean of type 'com.service.ThirdUserService' that could not be found.`
- 10.`Resolved[org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]`
- 11. `org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mapper.UserMapper.login`
- 12. 方法走不到,一直405!!
- 13. 项目启动报错:`java.sql.SQLNonTransientConnectionException: Could not create connection to database server`
- 14.项目启动报错:` org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionExcept ion: Could not create connection to database server. Attempted reconnect 3 times. Giving up.`
- 15. 页面404 `http://localhost:8080/oauth/authorize?response_type=code&client_id=admin&redirect_uri= http://localhost:8080&scope=all`
- 16. 项目运行报错`org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 : [no body]`
- 17. 使用lombok的`@slf4j`, `log.info()`编译通过,运行报错,log符号找不到
- 18. 项目启动报错:`A component required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found.`
1.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有关datasource
因为我pom依赖文件中引入了mybatisl依赖,spring自动装配,却没有找到配置数据源,因此tomcat启动时会检查配置,找不到就报错了,tomcat启动失败
出现这个错误就是datasource数据源的问题,看看是否配置了,配置文件中的格式有没有错误(yml缩进细节注意了)
不想配置就直接在启动类注解上加东西,把它排除掉,不检测它。
如:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
此外,微服务项目中报错14.Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto
,也是上述原因引起
父工程依赖有jdbc的相关配置,但子工程没有,启东时找不到配置就报错。
解决方法同上!
2. Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup
页面404
视图解析器问题 ,引入thymeleaf模板引擎
3. Error running 'SecurityTest.testPw': Failed to resolve org.junit.platform:junit-platform-launcher:1.5.2
原因:缺少测试对应的依赖
解决方法: 类文件中加上 import org.testng.annotations.Test; 后根据idea提示,加上包对应的依赖即可。
4. There was an unexpected error (type=Not Found, status=404).No message available
页面404!!
原因:直接访问springboot项目下的templates目录里的html文件报错,templates目录是受保护的,不能直接访问,可以由控制层转向
5. Encoded password does not look like BCrypt
直白翻译:加密后的密码不像是BCrypt加密过后的
这个是因为我当时代码里登录逻辑中明文密码是用BCrypt加密的,如:
@Bean
public PasswordEncoder getPw(){
return new BCryptPasswordEncoder();
}
@Resource
private PasswordEncoder pw;
....
....
//对用户输入的密码加密。这里没从前端取用户输入的,直接写了意思一下
String password = pw.encode("123456");
对比密码时是拿着这个加密过后的password和数据库中的对比
但是由于数据库里存的密码是明文(我忘改了),就报错了。。。
解决方法:数据库改成存密文
但是要注意,这个存的密文一定是要经过BCrypt(你代码中指定的那个加密算法)加密的,不然还是会报这个错误,。
一般注册的时候会把用户密码以密文形式存储到数据库(经过加密存到数据库),但是由于我这里是直接在数据库中写入用户测试数据,所以就不知道密文了,那怎么直接测试数据库密文?
如下,写个测试类,把加密后的密文输出,再直接写到数据库中去。
@SpringBootTest
public class SecurityTest {
@Test
public void testPw(){
PasswordEncoder pw = new BCryptPasswordEncoder();
//加密(盐不一样,每次加密的密文也不一样