提交 b9c6c5d7 编写于 作者: 武汉红喜's avatar 武汉红喜

examples annotation

上级 36e88642
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hongxi.whatsmars.dubbo.example.annotation;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.hongxi.whatsmars.dubbo.example.annotation.action.AnnotationAction;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* AnnotationConsumer
*/
public class AnnotationConsumer {
public static void main(String[] args) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
context.start();
final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
String hello = annotationAction.doSayHello("world");
System.out.println("result :" + hello);
System.in.read();
}
@Configuration
@EnableDubbo(scanBasePackages = "org.hongxi.whatsmars.dubbo.example.annotation.action", multipleConfig = true)
@PropertySource("classpath:dubbo-consumer.properties")
@ComponentScan(value = {"org.hongxi.whatsmars.dubbo.example.annotation.action"})
static public class ConsumerConfiguration {
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hongxi.whatsmars.dubbo.example.annotation;
import com.alibaba.dubbo.config.ProviderConfig;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* AnnotationProvider
*/
public class AnnotationProvider {
public static void main(String[] args) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
context.start();
System.in.read();
}
@Configuration
@EnableDubbo(scanBasePackages = "org.hongxi.whatsmars.dubbo.example.annotation.impl", multipleConfig = true)
@PropertySource("classpath:dubbo-provider.properties")
// @ComponentScan(value = {"com.alibaba.dubbo.examples.annotation.impl"})
static public class ProviderConfiguration {
@Bean
public ProviderConfig providerConfig() {
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setTimeout(1000);
return providerConfig;
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hongxi.whatsmars.dubbo.example.annotation.action;
import com.alibaba.dubbo.config.annotation.Reference;
import org.hongxi.whatsmars.dubbo.example.annotation.api.AnnotationService;
import org.springframework.stereotype.Component;
/**
* AnnotationAction
*/
@Component("annotationAction")
public class AnnotationAction {
@Reference
private AnnotationService annotationService;
public String doSayHello(String name) {
return annotationService.sayHello(name);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hongxi.whatsmars.dubbo.example.annotation.api;
/**
* AsyncService
*/
public interface AnnotationService {
String sayHello(String name);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hongxi.whatsmars.dubbo.example.annotation.impl;
import com.alibaba.dubbo.config.annotation.Service;
import org.hongxi.whatsmars.dubbo.example.annotation.api.AnnotationService;
/**
* AsyncServiceImpl
*/
@Service
public class AnnotationServiceImpl implements AnnotationService {
public String sayHello(String name) {
System.out.println("async provider received: " + name);
return "annotation: hello, " + name;
}
}
\ No newline at end of file
#<dubbo:application name="annotation-consumer"/>
dubbo.application.application-id.name=annotation-consumer
#<dubbo:registry id="registry-id" address="multicast://224.5.6.7:1234"/>
dubbo.registry.registry-id.address=zookeeper://127.0.0.1:2181
dubbo.consumer.consumer-id.timeout=3000
\ No newline at end of file
#<dubbo:application id="application-id" name="dubbo-annotation-provider"/>
dubbo.application.application-id.name=xxx
#<dubbo:registry id="registry-id" address="multicast://224.5.6.7:1234"/>
dubbo.registry.registry-id.address=zookeeper://127.0.0.1:2181
#<dubbo:protocol id="protocol-id" name="dubbo" port="12345"/>
dubbo.protocol.protocol-id.name=dubbo
dubbo.protocol.protocol-id.port=20883
\ No newline at end of file
......@@ -9,4 +9,12 @@ spring:
port: 20881
module:
name: demo
# scan:
\ No newline at end of file
# scan:
# protocol:
# dubbo:
# name: dubbo
# port: 20881
# hessian:
# name: hessian
# port: 8080
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册