@RpcService @Component public class UserServiceImpl implements UserService {......
Map<String, Object> services = applicationContext.getBeansWithAnnotation(RpcService.class); for (Map.Entry<String, Object> entry : services.entrySet()) { Object bean = entry.getValue(); Class<?>[] interfaces = bean.getClass().getInterfaces(); for (Class<?> inter : interfaces) { rpcServices.put(inter.getName(), bean); } } log.info("加载RPC服务数量:{}", rpcServices.size());
在UserServiceImpl类中有@Transactional(rollbackFor = Exception.class)的时候,bean.getClass().getInterfaces()无法获得UserService这个接口。
interfaces里面是
org.springframework.aop.SpringProxy
org.springframework.aop.framework.Advised
org.springframework.cglib.proxy.Factory