Open energicchainblock opened 7 years ago
后续会对动态代理类的hashcode和equals等方法进行简单实现。 不过正常情况下应该不会出现对motan refer动态代理类的判等操作呀?是注入时没有指定代理类的name吗
有办法解决吗?1.1.0版本仍然报没有hashCode错误
没办法,只好手动跳过,创建自定义的PersistenceAnnotationBeanPostProcessor,覆盖requiresDestruction,判断bean为接口时,直接跳过
import java.lang.reflect.Proxy;
import org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor;
public class CustomPersistenceAnnotationBeanPostProcessor extends PersistenceAnnotationBeanPostProcessor {
private static final long serialVersionUID = 6356435448579269667L;
@Override
public boolean requiresDestruction(Object bean) {
Class<? extends Object> clazz = bean.getClass();
//根据接口类特征修改条件
if (Proxy.isProxyClass(clazz) && 1 == clazz.getInterfaces().length) {
return false;
}
return super.requiresDestruction(bean);
}
}
注入bean
@Bean(AnnotationConfigUtils.PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME)
@Primary
public PersistenceAnnotationBeanPostProcessor persistenceAnnotationBeanPostProcessor() {
return new CustomPersistenceAnnotationBeanPostProcessor();
}
这个问题只在尝试使用@Autowired等注解注入的时候才会出现,如果使用@MotanReferer注入是不会出现这个问题的
当集成spring boot jpa,加载spring-orm。jar,由于org.springframework.beans.factory.support.PersistenceAnnotationBeanPostProcessor #requiresDestruction 会检查 rpc 对象的hashcode 方法,从而调研com.weibo.api.motan.proxy.RefererInvocationHandler#invoke 调研错误,抛出异常, can not invoke local method:hashCode