TomcatでSpring Bootを起動するときのユーザー名とパスワードは何ですか?質問する

TomcatでSpring Bootを起動するときのユーザー名とパスワードは何ですか?質問する

Spring Boot 経由で Spring アプリケーションをデプロイしてアクセスするときにlocalhost:8080認証が必要ですが、ユーザー名とパスワードは何ですか、またどのように設定できますか? これをファイルに追加しようとしましたtomcat-usersが、機能しませんでした:

<role rolename="manager-gui"/>
    <user username="admin" password="admin" roles="manager-gui"/>

これがアプリケーションの開始点です:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}

これは Tomcat の依存関係です:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

で認証するにはどうすればいいですかlocalhost:8080?

ベストアンサー1

クラスパスにSpring Securityがあり、Spring Securityがデフォルトのユーザーと生成されたパスワードで自動的に構成されていると思います。

pom.xml ファイルで次の点を確認してください。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

pom にこれが含まれている場合は、次のようなログ コンソール メッセージが表示されるはずです。

Using default security password: ce6c3d39-8f20-4a41-8e01-803166bb99b6

userブラウザのプロンプトで、コンソールに表示されたユーザーとパスワードをインポートします。

または、Spring Securityを設定したい場合は、Spring Boot のセキュリティ保護の例

Spring Bootで説明されている参照ドキュメントの中に安全セクションでは、次のことを示します。

The default AuthenticationManager has a single user (‘user’ username and random password, printed at `INFO` level when the application starts up)

Using default security password: 78fa095d-3f4c-48b1-ad50-e24c31d5cf35

おすすめ記事