java内省机制
At runtime and in the builder environment we need to be able to figure out which properties, events, and methods a Java Bean supports. We call this process introspection.
背景
之所以要了解这个概念,是修改了pom之后,线上出现了 Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class
的错误,其实本身就是因为spring尝试分析bean属性时发生的错误,大概率是依赖找不到,后面也是在后续的日志里发现了 ClassNotFound 的错误。
什么是内省机制
计算机程序在运行时(Runtime)检查对象(Object)类型的一种能力, 通常也可以称作运行时类型检查。
简单来说,可以用反射来理解,就是运行时能够动态的获取java bean的相关属性
java 内省机制的实现
java 提供了一套 api 来允许程序运行时获取对象的信息和实例的信息。 这些类在 java.beans
中,核心的类是 Introspector
。 本质上是反射的一层封装。