简体   繁体   中英

Java RMI port binding error in openshift

I have developed a small Spring based web application to test Spring RMI. There I have created a simple service to generate a greeting message based on the input parameter and return it back to the client. My spring context file looks like this:

<bean id="registry" 
class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">

  <property name="port" value="4777"/>

</bean>

<bean id="greetingService" class="com.greeting.GreetingServiceImpl" >
</bean>

<bean class="org.springframework.remoting.rmi.RmiServiceExporter"
      p:service-ref="greetingService"
      p:serviceName="greetingRmiService"
      p:serviceInterface="com.greeting.GreetingService"
      p:registry-ref="registry"
/>

First I have deployed this application in my local pc running tomcat server 7 and it deployed successfully. Then I have uploaded the war file of this application to Openshift tomcat 7 DIY server. But It doesn't deploy my application and gave this error in the log file.

SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registry' defined in ServletCo ntext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.rmi.serve r.ExportException: Port already in use: 4777; nested exception is: java.net.BindException: Permission denied at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowir eCapableBeanFactory.java:1420) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireC apableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCap ableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanReg istry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListab leBeanFactory.java:567) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractAppl icationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722) Caused by: java.rmi.server.ExportException: Port already in use: 4777; nested exception is: java.net.BindException: Permission denied at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:328) at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:236) at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411) at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147) at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:207) at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:123) at sun.rmi.registry.RegistryImpl.(RegistryImpl.java:109) at java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:203) at org.springframework.remoting.rmi.RmiRegistryFactoryBean.getRegistry(RmiRegistryFactoryBean.java:267) at org.springframework.remoting.rmi.RmiRegistryFactoryBean.getRegistry(RmiRegistryFactoryBean.java:236) at org.springframework.remoting.rmi.RmiRegistryFactoryBean.getRegistry(RmiRegistryFactoryBean.java:193) at org.springframework.remoting.rmi.RmiRegistryFactoryBean.afterPropertiesSet(RmiRegistryFactoryBean.java:164) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAuto wireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowir eCapableBeanFactory.java:1417) ... 26 more Caused by: java.net.BindException: Permission denied

How to fix this error and getting deployed this application in Openshift?

Thanks!

Port already in use: 4777

Use a port that isn't already in use.

OR make your sure application is really stopped before you restart it.

In OpenShift it is possible to bind to the internal IP with port range: 15000 - 35530. So, you can't use 4477. Use anything between 15000-35530. Also, understand that these are internal ports which means you can only use them from within application. Read more at https://www.openshift.com/kb/kb-e1038-i-cant-bind-to-a-port

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM