使用dubbo进行分布式开发,需要使用dubbo-admin在单机、集群下查看服务的调用。
一、下载
1、首先到github上下载,这个是分支地址,找到自己想要的版本:https://github.com/apache/incubator-dubbo/releases
二、dubbo-admin打包部署
首先进到dubbo-admin模块目录下。使用命令mvn package -Dmaven.test.skip=true。
之后,在dubbo-admin下级目录target中,能看见所生成的dubbo-admin-2.5.xx.war的war包,如下图示:
三、dubbo-admin打报错及解决
部署到Tomcat,发现项目报错,查看打印信息。
ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uriBrokerService': Cannot create inner bean '(inner bean)' of type [com.alibaba.citrus.service.uribroker.impl.URIBrokerServiceImpl$URIBrokerInfo] while setting bean property 'brokers' with key [0]; nested excepti
on is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#25': Cannot create inner bean 'server' of type [com.alibaba.citrus.service.uribroker.uri.GenericURIBroker] while setting constructor argument; nested exception is org.springframework.beans.fact
ory.BeanCreationException: Error creating bean with name 'server': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'URIType' of bean class [com.alibaba.citrus.service.uribroker.uri.GenericURIBroker]: Bean property 'URIType'
is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:287)
通过百度,发现虚拟机使用的是JDK1.8。需要修改下面的配置:
1、webx的依赖改为3.1.6版;
com.alibaba.citrus
citrus-webx-all
3.1.6
2、添加velocity的依赖,我用了1.7;
org.apache.velocity
velocity
1.7
3、对依赖项dubbo添加exclusion,避免引入旧spring
com.alibaba
dubbo
${project.parent.version}
org.springframework
spring
重新打包,发布Tomcat服务器,发现依然报404错,查看Tomcat日志。
6-Oct-2018 10:02:44.155 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\dubbo-admin.war]
16-Oct-2018 10:02:54.888 信息 [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
INFO: configuring "log4j" using file:/E:/InstallPackage/KFPackage/apache-tomcat-8.5.31/webapps/dubbo-admin/WEB-INF/log4j.xml
- with property localAddress = 192.168.100.100
- with property localHost = DESKTOP-1DFSV5L
- with property loggingCharset = UTF-8
- with property loggingLevel = INFO
- with property loggingRoot = C:\Users\Kyrie\logs
INFO context.ContextLoader - Root WebApplicationContext: initialization started
INFO support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Tue Oct 16 10:02:55 CST 2018]; root of context hierarchy
INFO xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:614)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:515)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4792)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5256)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
... 25 more
16-Oct-2018 10:02:55.573 严重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
16-Oct-2018 10:02:55.584 严重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/dubbo-admin] startup failed due to previous errors
INFO support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Tue Oct 16 10:02:55 CST 2018]; root of context hierarchy
WARN support.XmlWebApplicationContext - Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Tue Oct 16 10:02:55 CST 2018]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:427)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:999)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:583)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:116)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4839)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
16-Oct-2018 10:02:55.656 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\dubbo-admin.war] has finished in [11,500] ms
16-Oct-2018 10:02:55.661 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\docs]
16-Oct-2018 10:02:55.745 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\docs] has finished in [83] ms
16-Oct-2018 10:02:55.752 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\examples]
16-Oct-2018 10:02:57.497 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\examples] has finished in [1,745] ms
16-Oct-2018 10:02:57.498 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\host-manager]
16-Oct-2018 10:02:57.579 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\host-manager] has finished in [81] ms
16-Oct-2018 10:02:57.580 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\manager]
16-Oct-2018 10:02:57.645 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\manager] has finished in [65] ms
16-Oct-2018 10:02:57.646 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\ROOT]
16-Oct-2018 10:02:57.692 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [E:\InstallPackage\KFPackage\apache-tomcat-8.5.31\webapps\ROOT] has finished in [47] ms
16-Oct-2018 10:02:57.701 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
16-Oct-2018 10:02:57.720 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
16-Oct-2018 10:02:57.729 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 13683 ms
结果发现dubbo-admin并没有启动。出现一个异常,这个异常明显说没有找到一个叫applicationContext.xml的文件,然后完全蒙蔽,别人打包的没问题我打包的居然报错。
ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
通过谷歌,原来是spring版本太高要换成3.2.9.RELEASE
,然后找到incubator-dubbo-dubbo-2.5.4
下的pom.xml找到spring的版本改成3.2.9.RELEASE
。
重新打包,再部署Tomcat,发现依然报错,查看Tomcat日志:
java.net.UnknownHostException: linux-6cct.site: linux-6cct.site: Name or service not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1438)
at test.TestComm.doMain(TestComm.java:19)
at test.TestComm.main(TestComm.java:13)
Caused by: java.net.UnknownHostException: linux-6cct.site: Name or service not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:866)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1258)
at java.net.InetAddress.getLocalHost(InetAddress.java:1434)
通过修改/etc/hosts文件
127.0.0.1 主机名 localhost.localdomain localhost
或是再添加一条
127.0.0.1 主机名
解决主机名问题。
重新部署,问题解决。
参考资料:https://blog.csdn.net/qq_22067469/article/details/83069851