betfair / cougar

Cougar is a framework for making building network exposed service interfaces easy.
http://betfair.github.io/cougar
Apache License 2.0
27 stars 18 forks source link

Switch to using classpath resources for PropertyConfigurer #20

Closed eswdd closed 10 years ago

eswdd commented 10 years ago

We have an issue with cougar platform and could use your assistance.

When running any of our (non-Cougar) applications, we need to override cougar’s com.betfair.cougar.util.configuration.PropertyConfigurer or the application will not run.

The problem we are facing is related to the defaultConfig setter (PropertyConfigurer.setDefaultConfig). This setter is used by Spring to inject the resource in four different xml files, in which the resource is contained in a sub-folder named “conf”. As the path is given as a String starting at the root of the jar (e.g. ), the path is resolved as a ServletContextResource (due to the ‘/’), instead of a ClassPathResource. In light of this, the application fails during startup as a FileNotFoundException is thrown (i.e. such ServletContextResource does not exist).

In order to fix this problem, we are overriding the class (PropertyConfigurer) and altering the setDefaultConfig method to take a String (instead of a Resource), resolving the String ourselves (i.e. this.defaultConfig = new DefaultResourceLoader().getResource(defaultConfig)). This solution does not require any changes in the xml files.

A different (possible) solution to this problem would be to include a “classpath:” prefix on the four xml files (in the defaultConfig property location): (cougar-core-impl-2.9.6.jar) conf.core-config-cougar-core-impl.xml (cougar-client-2.9.6.jar) conf.cougar-application-spring.xml (cougar-marshalling-impl-2.9.6.jar) module-config-cougar-marshalling.xml (cougar-standalone-ev-2.9.6.jar) module-config-cougar-standalone-ev.xml.