In order to cater for all of spring's configuration, add no XML configuration implementation, here does not compare the pros and cons of the two ways, please make a reasonable choice according to the usage habits of the project.
1. Module description
Implement spring's javaconfig configuration by Main.main(args) javaconfig scanning dubbo.spring.javaconfig All of the spring configuration classes directly under the package using the (Require parameter setting using Javaconfigcontainer) to boot
2. Using the example
Using the example in the Dubbo-demo/dubbo-demo-consumer module, the related configuration method references the annotation configuration
2.1 Code Explanation
dubbo-demo-consumer/../DubboDemoConsumerConfigEquivalent todubbo-demo-consumer/../dubbo-demo-consumer.xml
dubbo-demo-consumer/../DubboDemoActionConfigEquivalent todubbo-demo-consumer/../dubbo-demo-action.xml
dubbo-demo-consumer/../DemoJavaConfigActionEquivalent todubbo-demo-consumer/../DemoAction
dubbo-demo-consumer/../DemoJavaConfigConsumerTo start the sample program in Javaconfig mode
2.2 Example Demo
- Run dubbo-demo-provider/. /demoprovider
- Run dubbo-demo-consumer/. /demojavaconfigconsumer
- View Console output
3. No XML configuration
To convert the XML configuration mode to the Javaconfig configuration, the configuration classes not covered in the demo, refer to the API configuration implementation
@Configuration Public classDubbodemoconsumerconfig { Public Static FinalString application_name = "Consumer-of-helloworld-app"; Public Static FinalString registry_address = "zookeeper://127.0.0.1:2181"; Public Static FinalString annotation_package = "Com.alibaba.dubbo.demo.consumer"; @Bean Publicapplicationconfig Applicationconfig () {applicationconfig applicationconfig=NewApplicationconfig (); Applicationconfig.setname (application_name); returnApplicationconfig; } @Bean Publicregistryconfig Registryconfig () {registryconfig registryconfig=NewRegistryconfig (); Registryconfig.setaddress (registry_address); returnRegistryconfig; } @Bean PublicAnnotationbean Annotationbean () {Annotationbean Annotationbean=NewAnnotationbean (); Annotationbean.setpackage (Annotation_package); returnAnnotationbean; }}
Configuring Dubbox using the Javaconfig method