「url」属性が指定されておらず、埋め込みデータソースを構成できませんでした。サインインしてください

1. Spring Initializr はモジュールを迅速に作成します

1.1 Spring Initializr はモジュールを迅速に作成します

ここに画像の説明を挿入
希望のシーンを選択します。

Spring Web Web
Thymeleaf  页面
Spring Security 安全
MyBatis Framework 访问数据库

ここに画像の説明を挿入
ここに画像の説明を挿入
HelloController を作成します。
ここに画像の説明を挿入

こんにちはコントローラー

package com.djc.boot.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author JIACHENGER
 * @Description
 * @since 2023/7/18 15:17
 */
@RestController
public class HelloController {
    
    

    //响应浏览器发送的haha请求
    @GetMapping("/haha")
    public String hello() {
    
    
        return "Hello!2023718";

    }


}

1.2 Spring Initializer 作成ウィザード - ワンクリックでプロジェクト構造全体を作成

ここに画像の説明を挿入

2、「url」属性が指定されておらず、埋め込みデータソースを構成できませんでした

開始に失敗しました:

Description:

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

ここに画像の説明を挿入
理由: mybatis の依存関係は導入後に使用する必要があるため、一時的に使用しない場合はオフにしておかないとエラーが報告されます。
解決策: mybatis に関連するすべての依存関係をコメント化します(次に、Maven の下の最初のアイコンをクリックしてリロードすると、依存関係内の mybatis 関連の依存関係が削除されます)
ここに画像の説明を挿入
mybatis 関連の依存関係に注釈を付けた後の pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.1</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.djc.boot</groupId>
    <artifactId>boot3-02-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>boot3-02-demo</name>
    <description>boot3-02-demo</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    <!--    <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.2</version>
        </dependency>-->
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity6</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
<!--        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter-test</artifactId>
            <version>3.0.2</version>
            <scope>test</scope>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

三、サインインしてください

3.1 生成されたセキュリティパスワードの使用: 7d2b9a84-e6b6-47b3-8b43-dddde85dbbde

ここに画像の説明を挿入

3.2 サインインしてください

8080 にアクセスすると、ブラウザにサインインしてくださいウィンドウが表示されます:
ここに画像の説明を挿入
Postman を使用して 401 をテストします。許可がありません:
ここに画像の説明を挿入
理由: SpringSecurityまたは Spring Boot によって提供されるセキュリティ自動構成クラスSecurityAutoConfigurationの依存関係(つまり、SpringSecurity が自動的に統合されます) 。

解決策: SpringSecurity の依存関係の自動構成をキャンセルします。

spring启动类上加@SpringBootApplication(exclude={
    
    SecurityAutoConfiguration.class})  

また

spring启动类上加@SpringBootApplication(exclude={
    
    SecurityAutoConfiguration.class,SecurityFilterAutoConfiguration.class})

SpringSecurity の依存関係の自動構成をキャンセルします。

package com.djc.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;


/**
 * @author JIACHENGER
 */
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
public class Boot302DemoApplication {
    
    

    public static void main(String[] args) {
    
    
        SpringApplication.run(Boot302DemoApplication.class, args);
    }

}

ここに画像の説明を挿入

3.3 正常に開始する

ここに画像の説明を挿入

3.3.1 ホワイトラベルのエラーページ

http://localhost:8080/ にアクセスしてください
ここに画像の説明を挿入
。 理由: 処理するリクエストが書き込まれていないため、無視できます。

package com.djc.boot.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author JIACHENGER
 * @Description
 * @since 2023/7/18 15:17
 */
@RestController
public class HelloController {
    
    

    //响应浏览器发送的haha请求
    @GetMapping("/haha")
    public String hello() {
    
    
        return "Hello!2023718";

    }


}

3.3.2 haha​​ にアクセスします: http://localhost:8080/haha

ここに画像の説明を挿入

3.3.3 郵便配達員アクセス笑リクエスト

ここに画像の説明を挿入

4. 参考文献

適切なドライバー クラスの処理メソッドを決定できませんでした
springboot-inexplicable ログイン インターフェイス「サインインしてください」
突然「サインインしてください」ページ
Spring Boot セキュリティ自動構成
05 クイック スタート: Spring Initializer

おすすめ

転載: blog.csdn.net/qyfx123456/article/details/131798396