您好我正在尝试使用我在java类中的.cfg文件中定义的属性。我正在尝试访问service.storeurl。这是我的属性文件:
service.protocol=http
service.host=localhost
service.port=8080
service.context=newservice
service.storeurl=[[service.protocol]]\://[[service.host:service.port]]/[[service.context]]/docs
当我在java中使用它时,我没有获得service.protocol,service.host,service.port n all的值。这是我得到的错误:
java.net.MalformedURLException: no protocol: [[service.protocol]]://[[service.host:service.port]]/[[service.context]]/docs
at java.net.URL.<init>(URL.java:586)[:1.8.0_45]
at java.net.URL.<init>(URL.java:483)[:1.8.0_45]
at java.net.URL.<init>(URL.java:432)[:1.8.0_45]
at com.newservice.processor.NewProcessor.process(PingProcessor.java:30)[465:newservice:1.0.0.SNAPSHOT]
at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:51)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:139)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:113)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.component.cxf.CxfConsumer$1.asyncInvoke(CxfConsumer.java:95)[207:org.apache.camel.camel-cxf:2.15.1.redhat-621084]
at org.apache.camel.component.cxf.CxfConsumer$1.invoke(CxfConsumer.java:75)[207:org.apache.camel.camel-cxf:2.15.1.redhat-621084]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_45]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_45]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$2.run(ServiceInvokerInterceptor.java:126)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:131)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:212)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)[82:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0.0]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:69)[93:org.ops4j.pax.web.pax-web-jetty:3.2.5]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:240)[93:org.ops4j.pax.web.pax-web-jetty:3.2.5]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)[93:org.ops4j.pax.web.pax-web-jetty:3.2.5]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.Server.handle(Server.java:370)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[86:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_45]
我已经以类似的方式定义了其他属性,我可以在我的java类中访问它们。只有这一个属性无法访问。有什么想法吗?
答案 0 :(得分:0)
您使用什么工具来解析cfg文件?普通的java属性没有机制来解析双括号中的属性引用。
因此,只要您将文件作为普通属性文件读取,service.storeurl
的值就是文字字符串“[[service.protocol]]:// [[service.host:service.port] ] / [[service.context]] /文档”。
没有替换令牌。