Home  >  Article  >  Java  >  Detailed explanation of annotated Dubbo service configuration examples

Detailed explanation of annotated Dubbo service configuration examples

零下一度
零下一度Original
2017-06-28 09:11:002555browse

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" />
2. Add Dubbo Service annotation to the Service implementation class
import com.alibaba.dubbo.config.annotation.Service;

@Servicepublic class DubboServiceImpl implements DubboService {
}
2. Service consumer
1. Add Dubbo annotation scanning in Dubbo configuration file (same as service provider)
<!-- 开启dubbo注解支持 -->
<!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 -->
<dubbo:annotation package="com.bounter" />
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"/>
3. After the Dubbo service is introduced into the controller, it can be used
@Referenceprivate DubboService dubboService;

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn