Search in sources :

Example 1 with SpringImplementationImpl

use of com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl in project sofa-boot by alipay.

the class ServiceAnnotationBeanPostProcessor method processSofaService.

private void processSofaService(Object bean, String beanName) {
    final Class<?> beanClass = AopProxyUtils.ultimateTargetClass(bean);
    SofaService sofaServiceAnnotation = beanClass.getAnnotation(SofaService.class);
    if (sofaServiceAnnotation == null) {
        return;
    }
    Class<?> interfaceType = sofaServiceAnnotation.interfaceType();
    if (interfaceType.equals(void.class)) {
        Class<?>[] interfaces = beanClass.getInterfaces();
        if (interfaces == null || interfaces.length == 0 || interfaces.length > 1) {
            throw new ServiceRuntimeException("Bean " + beanName + " does not has any interface or has more than one interface.");
        }
        interfaceType = interfaces[0];
    }
    Implementation implementation = new SpringImplementationImpl(beanName, applicationContext);
    implementation.setTarget(bean);
    Service service = new ServiceImpl(sofaServiceAnnotation.uniqueId(), interfaceType, InterfaceMode.annotation, bean);
    service.addBinding(new JvmBinding());
    ComponentInfo componentInfo = new ServiceComponent(implementation, service, sofaRuntimeContext);
    sofaRuntimeContext.getComponentManager().register(componentInfo);
}
Also used : ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ServiceImpl(com.alipay.sofa.runtime.service.component.impl.ServiceImpl) Service(com.alipay.sofa.runtime.service.component.Service) SofaService(com.alipay.sofa.runtime.api.annotation.SofaService) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SofaService(com.alipay.sofa.runtime.api.annotation.SofaService) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) SpringImplementationImpl(com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Aggregations

ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)1 SofaService (com.alipay.sofa.runtime.api.annotation.SofaService)1 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)1 Service (com.alipay.sofa.runtime.service.component.Service)1 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)1 ServiceImpl (com.alipay.sofa.runtime.service.component.impl.ServiceImpl)1 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)1 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)1 SpringImplementationImpl (com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl)1