You'll have to subclass ResourceLocator and implement it:

    /**

     * Finds a collection of matching resources for a given name. The name
components must

     * be separated by forward slashes.

     */

    Collection<Resource> findResources(String name);



For example, The name portion could just be the file name
"cayenne-blah.xml", and your subclass could hardcode the directory path.
The logic could be copied from FilesystemResourceLocator:


            File resourceFile = *new* File(root, name);

            *if* (resourceFile.exists()) {

                *try* {

                    resources.add(*new* URLResource(resourceFile
.toURI().toURL()));

                }

                *catch* (MalformedURLException e) {

                    *throw* *new* CayenneRuntimeException("Can't convert
file to URL: %s", e,  resourceFile.getAbsolutePath());

                }

            }



Binding it using DI looks like this:


        // a locator of resources, such as XML descriptors

        binder.bind(ResourceLocator.*class*).to(MyResourceLocator.*class*);

        binder.bind(Key.*get*(ResourceLocator.*class*, Constants.
*SERVER_RESOURCE_LOCATOR*)).to(MyResourceLocator.*class*);


On Fri, Oct 11, 2019 at 8:57 AM Andrew Willerding <awillerd...@itsurcom.com>
wrote:

> I have hopefully a quick question on how Cayenne can be configured to
> use a configuration file outside of a JAR/WAR.
>
> I currently use this to reference an absolute file path for my Cayenne
> files but I see that FilesystemResourceLocator is now deprecated ...
>
>              Module myModule = (org.apache.cayenne.di.Binder binder) -> {
>                  binder.bind(ResourceLocator.class).toInstance(new
> FilesystemResourceLocator(filePathForCayenne));
>                  ...
>
> What is the "new" way to replicate the same functionality.  The
> deprecated notes just provide the same example I'm already using.
>
> Thanks,
>
> Andrew
>
>
>
>

Reply via email to