blob: 0183a67a5b54e75edf761c8374625bc7dc94a113 [file] [log] [blame]
/*
* 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.apache.dubbo;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Consumer {
// Define a private variable (Required in Spring)
private UserProvider userProvider;
// Spring DI (Required in Spring)
public void setUserProvider(UserProvider u) {
this.userProvider = u;
}
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/dubbo.consumer.xml","META-INF/spring/service.xml");
context.start();
context.getBean(Consumer.class).start();
}
// Start the entry function for consumer (Specified in the configuration file)
public void start() {
System.out.println("\n\ntest");
testGetUser();
}
private void testGetUser() {
try {
User user1 = userProvider.GetUser("A003");
System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
" UserInfo, ID:" + user1.getID() + ", name:" + user1.getName()
+ ", age:" + user1.getAge() + ", time:" + user1.getTime().toString());
} catch (Exception e) {
System.out.println("*************exception***********");
e.printStackTrace();
}
}
}