You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/06 06:16:58 UTC

[GitHub] [dubbo] gaohuanjie commented on issue #8213: Dubbo 3.0.0中使用xml配置无效,只有在properties中配置才有效

gaohuanjie commented on issue #8213:
URL: https://github.com/apache/dubbo/issues/8213#issuecomment-874491130


   > > Dubbo 3.0.0中使用xml配置dubbo.application.name和dubbo.registry.address无效,只有在properties中配置才有效!
   > 
   > Hi, I have test your description, but in my case, it seems well use xml to config application name and registry address. How did you use it, can you describe it detaily, thanks.
   
   pom.xml文件:
   `<?xml version="1.0" encoding="UTF-8"?>
   
   <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
   
       <groupId>org.example</groupId>
       <artifactId>provider</artifactId>
       <version>1.0-SNAPSHOT</version>
   
       <name>provider</name>
       <!-- FIXME change it to the project's website -->
       <url>http://www.example.com</url>
   
       <properties>
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
           <maven.compiler.source>1.7</maven.compiler.source>
           <maven.compiler.target>1.7</maven.compiler.target>
       </properties>
   
       <dependencies>
           <dependency>
               <groupId>org.slf4j</groupId>
               <artifactId>slf4j-simple</artifactId>
               <version>1.6.6</version>
           </dependency>
   
           <!-- 引入dubbo依赖 -->
           <dependency>
               <groupId>org.apache.dubbo</groupId>
               <artifactId>dubbo</artifactId>
               <version>3.0.0</version>
           </dependency>
   
           <dependency>
               <groupId>org.apache.dubbo</groupId>
               <artifactId>dubbo-dependencies-zookeeper</artifactId>
               <version>3.0.0</version>
               <type>pom</type>
               <exclusions>
                   <exclusion>
                       <groupId>org.slf4j</groupId>
                       <artifactId>slf4j-log4j12</artifactId>
                   </exclusion>
                   <exclusion>
                       <groupId>org.apache.zookeeper</groupId>
                       <artifactId>zookeeper</artifactId>
                   </exclusion>
               </exclusions>
           </dependency>
   
           <dependency>
               <groupId>org.apache.zookeeper</groupId>
               <artifactId>zookeeper</artifactId>
               <version>3.6.3</version>
               <exclusions>
                   <exclusion>
                       <groupId>org.slf4j</groupId>
                       <artifactId>slf4j-log4j12</artifactId>
                   </exclusion>
               </exclusions>
           </dependency>
       </dependencies>
   
       <build>
           <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
               <plugins>
                   <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
                   <plugin>
                       <artifactId>maven-clean-plugin</artifactId>
                       <version>3.1.0</version>
                   </plugin>
                   <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                   <plugin>
                       <artifactId>maven-resources-plugin</artifactId>
                       <version>3.0.2</version>
                   </plugin>
                   <plugin>
                       <artifactId>maven-compiler-plugin</artifactId>
                       <version>3.8.0</version>
                   </plugin>
                   <plugin>
                       <artifactId>maven-surefire-plugin</artifactId>
                       <version>2.22.1</version>
                   </plugin>
                   <plugin>
                       <artifactId>maven-jar-plugin</artifactId>
                       <version>3.0.2</version>
                   </plugin>
                   <plugin>
                       <artifactId>maven-install-plugin</artifactId>
                       <version>2.5.2</version>
                   </plugin>
                   <plugin>
                       <artifactId>maven-deploy-plugin</artifactId>
                       <version>2.8.2</version>
                   </plugin>
                   <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
                   <plugin>
                       <artifactId>maven-site-plugin</artifactId>
                       <version>3.7.1</version>
                   </plugin>
                   <plugin>
                       <artifactId>maven-project-info-reports-plugin</artifactId>
                       <version>3.0.0</version>
                   </plugin>
               </plugins>
           </pluginManagement>
       </build>
   </project>
   `
   application.xml:
   `<?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   		http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
   
   	<!--配置应用名-->
       <dubbo:application name="service-provider"/>
       <!--配置注册中心-->
       <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
       <!--使用dubbo协议,将服务暴露在20880端口  -->
       <dubbo:protocol name="dubbo" port="20880"/>
       <bean id="userService" class="com.jd.service.UserService"></bean>
       <!-- 指定需要暴露的服务 -->
       <dubbo:service interface="com.jd.service.IUserService" ref="userService"/>
   </beans>`
   ServiceProvider.java:
   `package com.jd.test;
   
   import com.jd.service.IUserService;
   import org.springframework.context.support.ClassPathXmlApplicationContext;
   
   import java.io.IOException;
   
   public class ServiceProvider {
   
       public static void main(String[] args) {
           ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
           IUserService userService = context.getBean(IUserService.class);
           System.out.println(userService);
           try {
               System.in.read();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
   }`
   启动ZooKeeper服务器—>运行ServiceProvider.java,出现如下异常:
   `[INFO ]-[2021-07-06 14:16:06] -org.apache.dubbo.config.bootstrap.DubboBootstrap.checkDefaultAndValidateConfigs(DubboBootstrap.java:618) - [DUBBO] Ignore invalid config: <dubbo:application protocol="dubbo" hostname="Timmy" />, dubbo version: 3.0.0, current host: 10.10.13.156
   [INFO ]-[2021-07-06 14:16:06] -org.apache.dubbo.config.DubboShutdownHook.run(DubboShutdownHook.java:61) - [DUBBO] Run shutdown hook now., dubbo version: 3.0.0, current host: 10.10.13.156
   Exception in thread "main" java.lang.IllegalStateException: Default config not found for ApplicationConfig
   	at org.apache.dubbo.config.bootstrap.DubboBootstrap.checkDefaultAndValidateConfigs(DubboBootstrap.java:633)
   	at org.apache.dubbo.config.bootstrap.DubboBootstrap.checkGlobalConfigs(DubboBootstrap.java:583)
   	at org.apache.dubbo.config.bootstrap.DubboBootstrap.initialize(DubboBootstrap.java:556)
   	at org.apache.dubbo.config.bootstrap.DubboBootstrap.start(DubboBootstrap.java:1085)
   	at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onContextRefreshedEvent(DubboBootstrapApplicationListener.java:70)
   	at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onApplicationContextEvent(DubboBootstrapApplicationListener.java:63)
   	at com.alibaba.spring.context.OnceApplicationContextEventListener.onApplicationEvent(OnceApplicationContextEventListener.java:52)
   	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
   	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
   	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
   	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
   	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
   	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:898)
   	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554)
   	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
   	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
   	at com.jd.test.ServiceProvider.main(ServiceProvider.java:11)
   2568 [SpringContextShutdownHook] WARN org.springframework.context.support.ClassPathXmlApplicationContext - Exception thrown from ApplicationListener handling ContextClosedEvent
   java.lang.RuntimeException: java.lang.IllegalStateException: Dubbo config was cleaned prematurely
   	at org.apache.dubbo.common.function.ThrowableAction.execute(ThrowableAction.java:48)
   	at org.apache.dubbo.common.lang.ShutdownHookCallbacks.lambda$callback$0(ShutdownHookCallbacks.java:70)
   	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
   	at org.apache.dubbo.common.lang.ShutdownHookCallbacks.callback(ShutdownHookCallbacks.java:70)
   	at org.apache.dubbo.config.DubboShutdownHook.callback(DubboShutdownHook.java:77)
   	at org.apache.dubbo.config.DubboShutdownHook.run(DubboShutdownHook.java:64)
   	at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onContextClosedEvent(DubboBootstrapApplicationListener.java:74)
   	at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onApplicationContextEvent(DubboBootstrapApplicationListener.java:65)
   	at com.alibaba.spring.context.OnceApplicationContextEventListener.onApplicationEvent(OnceApplicationContextEventListener.java:52)
   	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
   	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
   	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
   	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
   	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
   	at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1013)
   	at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:949)
   Caused by: java.lang.IllegalStateException: Dubbo config was cleaned prematurely
   	at org.apache.dubbo.config.bootstrap.DubboBootstrap.checkConfigState(DubboBootstrap.java:1481)
   	at org.apache.dubbo.config.bootstrap.DubboBootstrap.destroy(DubboBootstrap.java:1448)
   	at org.apache.dubbo.common.function.ThrowableAction.execute(ThrowableAction.java:46)
   	... 15 more
   2571 [SpringContextShutdownHook] INFO org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor - class org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor was destroying!
   [INFO ]-[2021-07-06 14:16:06] -org.apache.dubbo.registry.support.AbstractRegistryFactory.destroyAll(AbstractRegistryFactory.java:94) - [DUBBO] Close all registries [], dubbo version: 3.0.0, current host: 10.10.13.156
   [ERROR]-[2021-07-06 14:16:06] -org.apache.dubbo.config.bootstrap.DubboBootstrap.checkConfigState(DubboBootstrap.java:1480) - [DUBBO] Dubbo config was cleaned prematurely, dubbo version: 3.0.0, current host: 10.10.13.156
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org