小编use*_*714的帖子

以编程方式将Bean添加到Spring Web App上下文

由于插件架构,我正在尝试以编程方式将bean添加到我的webapp中.我有一个通过@Component注释创建的Spring bean ,我正在实现该ApplicationContextAware接口.

我的覆盖功能如下所示:

@Override
public void setApplicationContext(ApplicationContext applicationContext)
        throws BeansException {

    // this fails
    this.applicationContext = (GenericWebApplicationContext) applicationContext;
 }
Run Code Online (Sandbox Code Playgroud)

基本上,我无法弄清楚如何将bean添加到setApplicationContext的applicationContext对象.任何人都可以告诉我我是怎么做错的方式吗?

好的,这就是我最终得到的解决方案:

@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry bdr)
        throws BeansException {
    BeanDefinition definition = new RootBeanDefinition(
            <My Class>.class);

    bdr.registerBeanDefinition("<my id>", definition);
}
Run Code Online (Sandbox Code Playgroud)

java spring web-applications dynamic

52
推荐指数
3
解决办法
10万
查看次数

尝试访问Web服务时,Apache Axis2抛出NoSuchMethodError吗?

我正在尝试使用axis2来访问以下Web服务:http : //www.webservicex.net/geoipservice.asmx? WSDL

我在本地拥有Axis2,并且通过将wsdl下载到本地驱动器并运行来生成类:

./wsdl2java.sh -uri geoipservice.wsdl -p geoip -d xmlbeans -s -o geoip
Run Code Online (Sandbox Code Playgroud)

这产生了一个带有build.xml文件的构建目录,然后我在其中运行了“ ant”,并且在libs文件夹中产生了一个客户端jar。

我将此罐子放到类路径上,然后尝试使用以下代码来访问该服务:

GeoIPServiceStub stub = new GeoIPServiceStub("http://www.webservicex.net/geoipservice.asmx?WSDL");
GetGeoIPDocument req = GetGeoIPDocument.Factory.newInstance();
GetGeoIP gic = req.addNewGetGeoIP();
gic.setIPAddress("74.125.91.105");  // google.com
GetGeoIPResponseDocument resp = stub.getGeoIP(req);
System.out.println(resp.getGetGeoIPResponse().toString());
Run Code Online (Sandbox Code Playgroud)

事情似乎在一开始就运行了,我看到结果又回到了syslog中,但是在完成之前它会抛出此异常:

java.lang.NoSuchMethodError: org.apache.axiom.om.impl.OMStAXWrapper.<init>(Lorg/apache/axiom/om/OMXMLParserWrapper;Lorg/apache/axiom/om/OMElement;Z)V
at org.apache.axiom.om.impl.llom.OMStAXWrapper.<init>(OMStAXWrapper.java:52)
at org.apache.axiom.om.impl.llom.OMElementImpl.getXMLStreamReader(OMElementImpl.java:795)
at org.apache.axiom.om.impl.llom.OMElementImpl.getXMLStreamReaderWithoutCaching(OMElementImpl.java:765)
at geoip.GeoIPServiceStub.fromOM(GeoIPServiceStub.java:767)
at geoip.GeoIPServiceStub.getGeoIP(GeoIPServiceStub.java:325)
Run Code Online (Sandbox Code Playgroud)

我到处都用Google搜索,却找不到导致这种情况的原因。谁能帮助我找到我做错了什么?谢谢。

apache axis2 web-services exception

0
推荐指数
1
解决办法
8102
查看次数