ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子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 系 / 依存除外している場合)
cglib
cglib
3.3.0
cglib
cglib-nodep
3.3.0
// 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 を除外している可能性があります:
org.springframework
spring-context
cglib
cglib
依存ツリーを調べる:
# Maven
mvn dependency:tree | grep -i cglib
# Gradle
./gradlew dependencies --configuration runtimeClasspath | grep -i cglib
# 結果に cglib が出てこなければ classpath に無い
対処4: ASM ライブラリの確認
CGLIB は ASM に依存します。cglib 通常版を使うときは ASM のバージョン衝突に注意:
org.ow2.asm
asm
9.5
cglib
cglib-nodep
3.3.0
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 ' ... ' for bean class [ ... ] conflicts with existing, non-compatible bean definition of same name and class [...]
- 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アノテーションとは
最近更新/作成されたページ
- Laravel キャッシュクリア完全ガイド(cache:clear / config:clear / 2026-05-18 07:42:07
- プロジェクトの作成と削除 2026-05-18 07:42:07
- インストール直後にNetbeansが反応しない 2026-05-18 07:42:07
- 動画やチャンネルの検索 2026-05-18 07:42:07
- APIキー取得方法 2026-05-18 07:42:07
- チャンネル情報の取得 2026-05-18 07:42:07
- API 入門 — Web API(REST / GraphQL / gRPC / 2026-05-18 07:42:07
- インストール(eclipseプラグイン) 2026-05-18 07:42:07
- Laravel「Dotenv values containing spaces must be surrounded 2026-05-18 07:42:07
- エラー一覧 2026-05-18 07:42:07
- curl: (51) SSL: certificate subject name '~' does not match 2026-05-18 07:42:07
- インストール方法(Windows版) 2026-05-18 07:42:07
- JSONから配列に変換 2026-05-18 07:42:07
- 処理を一定時間待つ 2026-05-18 07:42:07
- A non well formed numeric value encountered 2026-05-18 07:42:07
コメントを削除してもよろしいでしょうか?