4

My project uses spring and spring-dm for bean/service configuration. When I try to import an old project which also use spring for DI, bean will not be created.

An example to make clear,

I first define a url-alias in spring-appContext.xml

<bean name="xxxx" class="XRegistry" init-method="init">
    <property name="webRoot" value="/WebContent"></property>
    <property name="alias" value="/test"></property>
    <property name="cAliasPattern" value="/test/*.do" />
    <property name="conConfigFile" value="ddd.xml"/>
</bean>

in ddd.xml, I define some controller bean with url like /test/abc.do

No errors occur when launching as OSGi framework in eclipse. But when I try to access the URL(/test/abc.do),"Unknown OSGi URL:" is met.

The problem really confuses me is I am not clear where to start. My bundle has depended on spring bundles and have appContext.xml and dispatcher.xml. Just a normal spring usage scenario.

As spring looks like black box to me, I can only try some other possible reasons I can think, but haven't fixed it till now. Is somebody know how to moniter the spring startup process or helpful logs?

Thanks.

Edit when using spring-dm, you need to create a new fragment including log4j.properties to enable logging. This can help u to track spring startuping error.

As I explain in the 1st answer, the root cause is found, two choice,

  1. For those bundles exist in both workspace and target platform, increase the bundle's version in current workspace. When error happens , you should also look into the dependency bundles
  2. Remove the high version bundles in target platform.
Ivan
  • 766
  • 6
  • 17
  • Could someone give some suggestions? – Ivan Aug 07 '11 at 01:56
  • You haven't given anywhere near enough information for anyone to help you. You talk about a "url-mapping". What kind of mapping? How are you trying to access it, and why do you expect it to be available in the first place? – Ryan Stewart Aug 07 '11 at 03:24
  • @Ryan, I am wondering whether there's a general way to diagnose spring bean creation problem. Regarding my problem, I updated in the question section to make things clear. yes, I access the URL(/test/abc.do) ,and "Unknown URL" is met. From my usage of spring, by defining a validated spring configuration file in bundle and then run the bundle in spring ENV, the spring will handle all backend work. So I expect to access the URL successfully. – Ivan Aug 07 '11 at 05:12
  • I think you'd better seek help from someone who knows about the application you're working on. It seems that you don't know enough about it to even describe your problem. Some things to investigate: What is "XRegistry"? What is the mechanism that makes URLs available in an OSGi container? – Ryan Stewart Aug 08 '11 at 22:41
  • @Ryan, for business requirement, I don't specify the concrete java class name. I found the root cause, that is one bundle in dependency list for the service isn't startup for some configuration error. But I use some stupid way by checking one by one. Anyway, thanks for your help. – Ivan Aug 10 '11 at 02:17

1 Answers1

4

Have you tried setting the log level for the spring framework to debug?

E.g.

log4j.rootLogger=WARN, stdout
[...]
log4j.logger.org.springframework=DEBUG

This is always my first starting point when trying to diagnose problems with bean creation.

beny23
  • 34,390
  • 5
  • 82
  • 85
  • yes, I create a fragment to attach the log4j properties. And then I can see the spring log information. we are using the same way, right? – Ivan Aug 13 '11 at 15:47
  • yes, it displayes some NPE exception when creating OSGi service. I am using spring 2.5.5 and spring-osgi 1.1.0. I tried to import spring source code and the NPE is occured when creating export-package. However, my bundles explicitly exports packages. It really confuse me. But if you refresh the workspace several times, the NPE may be gone. So it's really tricky. – Ivan Aug 14 '11 at 06:36
  • 1
    Have you checked in which class the NPE occurs and where the object is created? – beny23 Aug 14 '11 at 08:03
  • Thanks god. I find the root cause.That is I am using two different framework. 1. Equniox for OSGi env 2. Spring-dm for dynamic service. For my scenario, bundles exist in both workspace and target platform and bundle in target is higher version that in current workspace, the equniox will active bundle in current workspace, however the spring-dm will take the high version plugin. When spring construct the context for this bundle, it will find that exported package is null as it's no actived. And also spring-dm 2.5 does't resove this NPE, so the problem happens. – Ivan Aug 16 '11 at 03:02
  • @beny23, I can't believe this doesn't have more upvotes. I remember doing this in the past but forgot the flag/syntax/logger name. Thanks for the info. – PatS Apr 16 '19 at 15:45