Configuring Dubbox using the Javaconfig method

Source: Internet
Author: User

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
    1. Run dubbo-demo-provider/. /demoprovider
    2. Run dubbo-demo-consumer/. /demojavaconfigconsumer
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.