Spring.NET ObjectDefinitionStoreException using assembly to store configuration files

StackOverflow https://stackoverflow.com/questions/16530740

  •  29-05-2022
  •  | 
  •  

Question

I am learning Spring.Net, I created a class MyApplication and a library class MyLib with all the spring configuration files that MyApplication needs.

I retrieve the metadata using:

IApplicationContext ctx = new XmlApplicationContext("assembly...");

I have three different xml files, one (springconfiguration.xml) imports the two other. At the beginning of my tries, my spring configuration files were at the root level of MyLib. Everything worked fine.

----- MyLib
-- Properties
-- References
-- commonspring.xml
-- buttonspring.xml
-- springconfiguration.xml

Then I created some folders in MyLib to store my xml files and it fails if I use subfolders:

the following works:

----- MyLib
--Properties
--References
--Common
    --commonspring.xml
--Gui   
    --buttonspring.xml
--Configuration
    --springconfiguration.xml

my springconfiguration.xml file is then:

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<import resource="Common/commonspring.xml"/>
<import resource="Gui/buttonspring.xml"/>
</objects>

and I retrieve the context with:

IApplicationContext ctx = new XmlApplicationContext("assembly://MyLib/MyLib/Configuration.springconfiguration.xml");

but if I use subfolders then it fails:

----- MyLib
--Properties
--References
--Common
    --commonspring.xml
--Gui
    --SpecialButton
        --buttonspring.xml
--Configuration
    --springconfiguration.xml

my springconfiguration.xml file is then:

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<import resource="Common/commonspring.xml"/>
<import resource="Gui/SpecialButton/buttonspring.xml"/>
</objects>

and I retrieve the context with:

IApplicationContext ctx = new XmlApplicationContext("assembly://MyLib/MyLib/Configuration.springconfiguration.xml");

The error is:

{"Error registering object defined in 'assembly [MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], resource [MyLib.Configuration.springconfiguration.xml] at line 5' : Invalid relative resource location 'Gui/SpecialButton/buttonspring.xml' to import object definitions from.\r\n<import resource=\"Gui/SpecialButton/buttonspring.xml\" xmlns=\"http://www.springframework.net\" />"}

I tried several syntaxes, I looked in the documentation and did not find any solution. Has someone an idee of where is the problem?

Update ok I found by myself: the correct syntaxe is:

<import resource="Gui.SpecialButton.buttonspring.xml"/>

then no errors are raised anymore and everything work fine.

Was it helpful?

Solution

To let everybody know here is the solution I found: in springconfiguration.xml instead of refering to the spring configuration file nested in folders as:

<import resource="Gui/SpecialButton/buttonspring.xml"/>

One has to write:

<import resource="Gui.SpecialButton.buttonspring.xml"/>

@marijn: thank you for your explanation, understanding a solution is better than just finding it ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top