Annotation-based Dubbo service configuration can greatly reduce the amount of Service configuration in the dubbo xml configuration file. The main steps are as follows:
1. Service provider
1. Add Dubbo annotation scanning in Dubbo configuration file
<!-- 开启dubbo注解支持 -->
<!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 -->
<dubbo:annotation package="com.bounter" />
Copy after login
Copy after login
2. Add Dubbo Service annotation to the Service implementation class
import com.alibaba.dubbo.config.annotation.Service;
@Servicepublic class DubboServiceImpl implements DubboService {
}
Copy after login
2. Service consumer
1. Add Dubbo annotation scanning in Dubbo configuration file (same as service provider)
<!-- 开启dubbo注解支持 -->
<!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 -->
<dubbo:annotation package="com.bounter" />
Copy after login
Copy after login
2. Introduce dubbo configuration into Spring MVC configuration to solve the problem of dubbo annotation incompatibility ( is very important, otherwise it is introduced into the controller The service will report a null pointer)
<!-- 引入dubbo配置,解决dubbo注解不兼容问题 -->
<import resource="classpath:spring-dubbo.xml"/>
Copy after login
3. After the Dubbo service is introduced into the controller, it can be used
@Referenceprivate DubboService dubboService;
Copy after login
The above is the detailed content of Detailed explanation of annotated Dubbo service configuration examples. For more information, please follow other related articles on the PHP Chinese website!