初學spring boot;第一次創建好spring boot的項目,開始想跑起來時,有兩個問題?(在https://start.spring.io/快速創建時,一般會遇到)

1、dataSource的url...是因爲 在application.properties沒有配置數據庫連接資源。

通常有兩個方法解決:a.在application.properties文件中配置數據庫資源

spring.datasource.url=jdbc:mysql://localhost:3306/xxxx?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.hikari.login-timeout=1000
spring.datasource.hikari.maximum-pool-size=30

b.添加註解,額,註解忘了。

2、啓動沒問題後,http://localhost:8080/login 發現需要認證登錄,是因爲在spring boot項目pom.xml中默認引入依賴

<dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-test</artifactId>
   <scope>test</scope>
</dependency>

一般解決方法有兩種:a.把這個依賴註釋掉。b.可以在IDEA控制檯看到登錄密碼,但是username卻是default,直接複製過去發現不行,其實密碼是沒錯,直接從控制檯把密碼複製過去,username其實默認是“user”,到這裏就可以登陸完成了,進行接下來的學習了。

3、寫個測試類,MyTest

這時在http://localhost:8080/MyTest/hello就可以看到返回的數據了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章