ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球
子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール
親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
| この記事の要点 |
|
このエラーの概要
Spring アプリ起動時に次のスタックトレースで失敗します:
Caused by: java.lang.IllegalStateException: CGLIB is required to process
@Configuration classes. Either add CGLIB to the classpath or remove the
following @Configuration bean definitions:
[appConfig]
at org.springframework.context.annotation.ConfigurationClassPostProcessor
.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:434)
これは Spring が @Configuration クラスを「実体クラスのまま」ではなく CGLIB 動的サブクラスとして動かそうとしたとき、CGLIB が classpath に居ないと発生します。
なぜ CGLIB が必要か
Spring は @Configuration クラスの @Bean メソッド間呼び出し(inter-bean reference)を制御するために、クラスを CGLIB でサブクラス化してプロキシ化します:
@Configuration
public class AppConfig {
@Bean
public UserRepository userRepository() {
return new UserRepository();
}
@Bean
public UserService userService() {
// ↓ この呼び出しが「都度 new UserRepository()」ではなく、
// Spring コンテナから既存のシングルトンを取得するように
// CGLIB プロキシによって書き換えられる
return new UserService(userRepository());
}
}
CGLIB が無いと、userRepository() 呼び出しが本当に都度 new されてしまい、シングルトンが崩れます。Spring はそれを許容せず起動時に止めます。
対処1: CGLIB 依存を追加(Spring 4 系 / 依存除外している場合)
<!-- Maven (pom.xml) -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
</dependency>
<!-- 依存解決問題を避けたいなら nodep 版(ASM を内包) -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.3.0</version>
</dependency>// Gradle (build.gradle)
dependencies {
implementation 'cglib:cglib:3.3.0'
// または nodep 版
implementation 'cglib:cglib-nodep:3.3.0'
}
対処2: proxyBeanMethods = false で CGLIB 不要に(Spring 5.2+)
inter-bean reference を使わないなら、CGLIB プロキシを完全に無効化できます:
// Spring 5.2 以降
@Configuration(proxyBeanMethods = false)
public class AppConfig {
@Bean
public UserRepository userRepository() {
return new UserRepository();
}
@Bean
public UserService userService(UserRepository repo) {
// ↑ メソッド呼び出しではなく、引数注入で受け取る
return new UserService(repo);
}
}
これで CGLIB は不要、起動も高速化。GraalVM Native Image でも有利。Spring Boot 2.2+ の @SpringBootConfiguration も内部で proxyBeanMethods = false 推奨パターンを採用しています。
| 設定 | 動作 | CGLIB | 起動時間 |
|---|---|---|---|
@Configuration(既定) | フルプロキシ、メソッド呼び出しを intercept | 必要 | 普通 |
@Configuration(proxyBeanMethods = false) | 軽量、メソッド呼び出しは普通の new | 不要 | 速い |
@Component | 同じく軽量、ただし @Bean メソッドは推奨されない | 不要 | 速い |
対処3: 依存除外を解除
誰かが exclusions で CGLIB / spring-core を除外している可能性があります:
<!-- ❌ こういう exclusions を消す -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
</exclusions>
</dependency>
依存ツリーを調べる:
# Maven
mvn dependency:tree | grep -i cglib
# Gradle
./gradlew dependencies --configuration runtimeClasspath | grep -i cglib
# 結果に cglib が出てこなければ classpath に無い
対処4: ASM ライブラリの確認
CGLIB は ASM に依存します。cglib 通常版を使うときは ASM のバージョン衝突に注意:
<!-- 衝突しがちな組み合わせ -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.5</version>
</dependency>
<!-- cglib-nodep は ASM を内包するので衝突しない(推奨) -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.3.0</version>
</dependency>
Spring Boot の場合
Spring Boot 2.x+ では spring-boot-starter が spring-core(内部に spring-asm + CGLIB 同等機能)を持っており、通常はこのエラーが出ません。出る場合は:
- 誰かが
spring-coreを除外している - Java バージョンが古い(Java 8 未満で動かそうとした)
- クラスローダー分離が極端(OSGi 等)
# Boot プロジェクトで spring-core が解決されているか
./gradlew dependencies --configuration runtimeClasspath | grep spring-core
# org.springframework:spring-core:5.3.x ← これがあれば CGLIB 機能あり
関連: Final クラス問題
CGLIB は対象クラスをサブクラス化するため、final クラスや final メソッドだとプロキシ化できません:
// ❌ NG: final クラス
@Configuration
public final class AppConfig { // ← Cannot subclass final class
@Bean
public Foo foo() { ... }
}
// ❌ NG: final メソッド
@Configuration
public class AppConfig {
@Bean
public final Foo foo() { ... } // ← Cannot subclass final method
}
// ✅ OK: 普通のクラス・メソッド
@Configuration
public class AppConfig {
@Bean
public Foo foo() { ... }
}
Kotlin の class は既定で final なので、open class にするか kotlin-spring プラグインを使用:
// Kotlin
@Configuration
open class AppConfig { // open 必須
@Bean
open fun foo(): Foo = Foo()
}
// または build.gradle.kts で
plugins {
kotlin("plugin.spring") version "1.9.0" // 自動 open
}
FAQ
Q: cglib と cglib-nodep、どちら?
A: nodep 版が安全。ASM を内包しているので、プロジェクトの ASM とバージョン衝突しません。
Q: Spring 5+ なのに出る
A: 1) 誰かが spring-core を除外、2) Maven shade plugin で誤って削除、3) クラスローダー分離問題、を確認。
Q: GraalVM Native Image で起動できない
A: CGLIB は動的バイトコード生成に依存し、Native Image と相性が悪いです。@Configuration(proxyBeanMethods = false) または Spring Native (Spring Boot 3 + AOT) を使用。
関連エラー
Cannot subclass final class— 対象クラスが final、Kotlin の場合はopen必須java.lang.NoClassDefFoundError: net/sf/cglib/proxy/Enhancer— CGLIB 自体が classpath に無い、対処1NoSuchMethodError: org.springframework.asm.ClassVisitor— Spring と ASM のバージョン不整合
ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球
子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール
親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
子ページはありません
- java.lang.IllegalStateException: CGLIB is required to process @Configuration classes
- Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
- No mapping found for HTTP request with URI ... in DispatcherServlet with name ...
- An internal error occurred during: "Building UI model". com/google/common/base/Function
- No identifier specified for entity : ...
- org.hibernate.hql.internal.ast.QuerySyntaxException: table_name is not mapped
- No compiler is provided in this environment
- java.sql.SQLException: The server time zone value ' ... ' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone
- Caused by: java.lang.RuntimeException: Executing an update/delete query
- Not supported for DML operations
- Field ... required a bean of type ... hat could not be found.
- Annotation-specified bean name 'xxxController' for bean class [com.xxx.controller.xxxController] conflicts with existing, non-compatible bean definition of same name and class [com.xxx.xxxController]
- Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
- Exception in thread "main" java.lang.UnsupportedClassVersionError
人気ページ
- 1 Eclipseで「サーバーに追加または除去できるリソースがありません。」の原因と対処法
- 2 tomcat の起動 / 停止ログと catalina.log・catalina.out の違い
- 3 JavaScript base URL 取得方法|window.location.origin と SSR/Node.js 対応
- 4 YouTube Data API v3 エラー一覧|403/400/404 の主要原因と切り分け
- 5 Spring Frameworkのアノテーション一覧
- 6 Laravel エラー一覧|500/Blade/DB 接続/ルーティングの代表エラー
- 7 3Dグラフィックスとは|モデリング/レンダリング/主要ソフトウェア (Blender / Maya)
- 8 【Spring】@Valueアノテーションとは
- 9 CATALINA_HOME の確認方法 (Linux / Mac)
- 10 【Spring】@Autowiredアノテーションとは
最近更新/作成されたページ
- IPv6とは|128bitアドレス・コロン16進表記/::省略・リンクローカル・SLAAC・デュアルスタック NEW 2026-06-22 12:34:44
- MAC アドレスフィルタリングの仕組みと限界 | ネットワーク入門 NEW 2026-06-22 12:19:10
- VPNとは|暗号トンネル・サイト間/リモートアクセス・IPsec/SSL-VPN/WireGuardを解説 NEW 2026-06-22 12:19:10
- WebSocket とは 全二重リアルタイム通信 ws/wss | ネットワーク入門 NEW 2026-06-22 12:17:25
- HTTP/2 とは 多重化・HPACK・バイナリフレーム | ネットワーク入門 NEW 2026-06-22 12:17:25
- Web通信プロトコル入門 HTTP/2・HTTP/3・WebSocket・gRPC・WebRTC | ネットワーク入門 NEW 2026-06-22 12:17:25
- gRPC とは HTTP/2 + Protocol Buffers の高速 RPC | ネットワーク入門 NEW 2026-06-22 12:17:25
- HTTP/3 (QUIC) とは UDP ベースの低遅延 Web 通信 | ネットワーク入門 NEW 2026-06-22 12:17:25
- WebRTC とは ブラウザ間 P2P の音声・映像・データ通信 | ネットワーク入門 NEW 2026-06-22 12:17:25
- 証明書と認証局(CA)とは|X.509・信頼チェーン・DV/OV/EV・失効(CRL/OCSP)を解説 NEW 2026-06-22 12:17:24
- ファイアウォールとは|パケットフィルタ・ステートフル・DMZ・次世代FW(L4/L7)を解説 NEW 2026-06-22 12:17:24
- iptables/nftablesとは|テーブル・チェーン・ルール例・永続化をLinux視点で解説 NEW 2026-06-22 12:17:24
- HAProxy とは frontend/backend と設定例 | ネットワーク入門 NEW 2026-06-22 12:17:24
- TLS/SSLの仕組み|ハンドシェイク・暗号スイート・前方秘匿性・証明書検証をわかりやすく解説 NEW 2026-06-22 12:17:24
- CDN とは エッジキャッシュ・TTL・Cloudflare/CloudFront | ネットワーク入門 NEW 2026-06-22 12:17:24
コメントを削除してもよろしいでしょうか?