Spring-namespaces allows you to define your own structure how spring beans could be configured. Very cool.
I have to use a 3rd party software (Assentis Docbase) which defines in its spring.schemas the following (example below simplified)
http\://com.apress.prospring2/ch07/custom.xsd=custDir:/custom.xsd
Meaning: If user defines in its spring-xml with schema-location: “http://com.apress.prospring2/ch07/custom.xsd” spring will validate this file against custom.xsd.
custDir is a directory OUTSIDE the provided jar. Does anyone have an idea how I can set this custDir to point to a valid path during junit test? I already tried -DcustDir=/pathToXsd/ but it did not work.
If I remove custDir than everything works as expected, but I can not remove it from provided spring.schemas since it is 3rd party software.
Maybe this is an issue how property-files are handled in java but I have no idea.
The syntax of
spring.schemasI provided in my question is a properitary definition of 3.rd party software. They implemented there ownEntityResolverwhich manually reacts on"custDir:"and starts some magic algorithm. So I came to the following workaround.You have to create your own
my_spring.schemaswhich must be live inMETA-INF/. Than you have to make sure that spring loadsmy_spring.schemasand NOTspring.schemas.I achieved it with implementing my own
TestingContextwhich is a subclass ofClassPathXmlApplicationContext. InTestingContextI overwrote methodprotected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOExceptionand filled it with implementation fromorg.springframework.context.support.AbstractXmlApplicationContext. The only change I made was to linebeanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this))tobeanDefinitionReader.setEntityResolver(new PluggableSchemaResolver(getClassLoader(), "META-INF/my_spring.schemas). And voila if I useTestingContextmy ownmy_spring.schemasis loaded.Drawback with this solution is that you have to provide all xsd in your jar because the default name, where spring looks up definitions has been changed.