今天继续《OSGi原理与最佳实践》,看到第四章,做 HelloWorld-cxf 的例子
照着例子敲来着,整个例子敲完了,运行,一直报错,
----------------这里是解决方法------------------
Dictionary<String, String> props = new Hashtable<String, String>(); props.put("osgi.remote.interfaces", "*"); props.put("osgi.remote.configuration.type", "pojo"); props.put("osgi.remote.configuration.pojo.address", "http://localhost:9000/hello_world"); registration = bundleContext.registerService(HelloWorldServiceInterfaces.class.getName(), new HelloWorldImple(), props);
Dictionary<String, String> props = new Hashtable<String, String>(); <span style="color:#ff0000;">props.put("service.exported.interfaces", "*"); props.put("service.exported.configs", "org.apache.cxf.ws"); props.put("org.apache.cxf.ws.address", "http://localhost:9000/hello_world");</span> registration = bundleContext.registerService(HelloWorldServiceInterfaces.class.getName(), new HelloWorldImple(), props);
---------------下面是故事,可以不看-------------------
不行,复制原来的代码直接贴过去(网上找的资源)还是一样。
各种缺包的提示,尝试着添加各种bundle,最后都要吐来了,还是提示缺,而且是越来越缺,完全一个无底洞。一定那里出问题了。
删除项目重新建,还好,这次不提示缺包了,这让我想起了,上一篇里面提到的,有可能是bundle以来问题,应该简单操作一下就行了,具体操作请查看
http://blog.csdn.net/q821424508/article/details/46604279
言归正传,说下今天的问题。
把项目弄好之后启动项目。没有错误提示,访问的时候抱404错误,控制台提示httpservice startup at 8080 ,这事什么意思,我代码里不是这么写的
Dictionary<String, String> props = new Hashtable<String, String>(); props.put("osgi.remote.interfaces", "*"); props.put("osgi.remote.configuration.type", "pojo"); props.put("osgi.remote.configuration.pojo.address", "http://localhost:9000/hello_world"); registration = bundleContext.registerService(HelloWorldServiceInterfaces.class.getName(), new HelloWorldImple(), props);
这问题就来了,启动不报错,但是访问不到路径,一定还是那里配置错误,
亲,没错的,代码都是复制过来的。那问题可有可能是版本的问题,我的环境,cxf插件下载的事最新的cxf-dosgi-ri-singlebundle-distribution-1.2.jar,
osgi也是比书里面的新,
别问我为什么不按照书里面的版本弄,我也想,只是有些资源时找不到的。所以就按照自己eclipse的默认版本来了。
说到版本不同,那就找下官网吧,
Note: for backwards compatibility old values marked below are still supported.
Property Name |
Data Type |
Example |
Description |
---|---|---|---|
service.exported.interfaces |
String |
|
Denotes the interfaces to be exposed remotely. This is a comma-separated list of fully qualified Java interfaces that should be made available remotely. A special value of |
service.exported.configs (previously:osgi.remote.configuration.type) |
String |
|
Specifies the mechanism for configuring the service exposure. Possible values:
|
这个事官网的,
Note: for backwards compatibility old values marked below are still supported.
这句翻译过来,应该是为了兼容老的功能,下面呗标记出来的依然支持吧,高中水平,不知道是不是这么翻译的。
但是按照翻译来说,我按照书上敲(别扣字眼,是复制来的我知道)的代码应该没问题
继续看
org.apache.cxf.ws
configuration type
When the service.exported.configs=org.apache.cxf.ws
(or osgi.remote.configuration.type=pojo
) property is specified, the following properties may also be specified.
突然来了一句,这句的大概意思是 如果service.exported.configs=org.apache.cxf.ws
(or osgi.remote.configuration.type=pojo
)
这个被指定了,
那么下面的也必须被设置,
我只能呵呵了 。
Property Name |
Data Type |
Example |
Description |
---|---|---|---|
org.apache.cxf.ws.address |
String |
{{ http://localhost:9090/greeter}} |
The address at which the service with be made available remotely. If this property is not specified, this defaults to {{ http://localhost:9000/fully/qualified/ClassName}}. |
org.apache.cxf.ws.httpservice.context |
String |
|
When this property is specified, the OSGi HTTP Service is used to expose the service, rather than a dedicated Jetty HTTP Server. This property doesn‘t allow the specification of a port number, as this is provided by the HTTP Service. The Distributed OSGi distributions come with Pax-Web, for which configuration information can be found here: http://wiki.ops4j.org/display/paxweb/Configuration, however other OSGi HTTP Service implementations are potentially configured differently. |
org.apache.cxf.ws.frontend |
String |
|
The CXF frontend which will be used to create endpoints. Defaults to ‘simple‘ which is an Aegis-based simple frontend. Note that for JAXWS to work a javax.jws.* has to be imported into the interface and/or implementation and client bundles for annotations like @WebService and @WebMethod be recognized |
org.apache.cxf.ws.databinding |
String |
|
Supported values are ‘aegis and ‘jaxb‘, defaults to ‘aegis‘. Note that for JAXB to work JAXB packages like javax.xml.bind.annotation.* have to be imported |
org.apache.cxf.ws.wsdl.location |
String |
|
WSDL location |
org.apache.cxf.ws.wsdl.service.ns |
String |
{{ http://services.org}} |
WSDL service namespace |
org.apache.cxf.ws.wsdl.service.name |
String |
|
WSDL service name |
org.apache.cxf.ws.wsdl.port.name |
String |
|
WSDL port name |
org.apache.cxf.ws.in.interceptors |
String, String[], List |
|
List of CXF in interceptors |
org.apache.cxf.ws.out.interceptors |
String, String[], List |
|
List of CXF out interceptors |
org.apache.cxf.ws.in.fault.interceptors |
String, String[], List |
|
List of CXF in fault interceptors |
org.apache.cxf.ws.out.fault.interceptors |
String, String[], List |
|
List of CXF out fault interceptors |
org.apache.cxf.ws.features |
String, String[], List, Object |
|
List of CXF out features |
org.apache.cxf.rs
configuration type
When the service.exported.configs=org.apache.cxf.rs
property is specified, the following properties may also be specified.
Property Name |
Data Type |
Example |
Description |
---|---|---|---|
org.apache.cxf.rs.address |
String |
{{ http://localhost:9090/greeter}} |
The address at which the service with be made available remotely. If this property is not specified, this defaults to {{ http://localhost:9000/fully/qualified/ClassName}}. |
org.apache.cxf.rs.httpservice.context |
String |
|
When this property is specified, the OSGi HTTP Service which is used to expose the service, rather than a dedicated Jetty HTTP Server. By default, absolute address may look like ‘http://localhost:8080/auction‘ |
org.apache.cxf.rs.provider |
Boolean |
|
Can be used to identify a global JAXRS provider as CXF-compatible |
org.apache.cxf.rs.provider.expected |
Boolean |
|
Can be used to require global providers to set an ‘org.apache.cxf.rs.provider‘ property with a value ‘true‘. |
org.apache.cxf.rs.provider.globalquery |
Boolean |
|
Can be used to disable queries for global providers, defaults to ‘true‘. |
org.apache.cxf.rs.databinding |
String |
|
This property has a limited value for JAXRS services as JAXB is supported by default, the only supported value is ‘aegis‘ and it is a shortcut for registering an Aegis provider, see below for more information on how to register custom providers for JAXRS services |
org.apache.cxf.rs.wadl.location |
String |
|
WADL location |
org.apache.cxf.rs.provider |
String, String[], List |
|
List of JAX-RS providers |
org.apache.cxf.rs.in.interceptors |
String, String[], List |
|
List of CXF in interceptors |
org.apache.cxf.rs.out.interceptors |
String, String[], List |
|
List of CXF out interceptors |
org.apache.cxf.rs.in.fault.interceptors |
String, String[], List |
|
List of CXF in fault interceptors |
org.apache.cxf.rs.out.fault.interceptors |
String, String[], List |
|
List of CXF out fault interceptors |
org.apache.cxf.rs.features |
String, String[], List |
|
List of CXF out features |
这么多,怎么设,算了,用最新的吧
Dictionary<String, String> props = new Hashtable<String, String>(); props.put("service.exported.interfaces", "*"); props.put("service.exported.configs", "org.apache.cxf.ws"); props.put("org.apache.cxf.ws.address", "http://localhost:9000/hello_world"); registration = bundleContext.registerService(HelloWorldServiceInterfaces.class.getName(), new HelloWorldImple(), props);
最新版的java代码是这样的,
能运行,能访问了,
我还是想吐糟一下,明明说要向下兼容,为什么要设置那么多额外的属性。
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/q821424508/article/details/46970419