简体   繁体   中英

Can IBM WebSphere Liberty Datasource be split from the server.xml into an include file?

Can IBM WebSphere Liberty handle splitting off the datasources/jndi entries from the server.xml into an include?

When I split the datasources out of the server.xml into it's own file, and include it as an include in the server.xml file below the library tags:

<include location="${server.config.dir}/datasources-join-include.xml"/>

And the datasources-join-include.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<server description="Datasource join include file">

  <dataSource id="db" jndiName="jdbc/Config">
     <jdbcDriver libraryRef="OracleLib"/>
     <properties.oracle URL="jdbc:oracle:xxx:@hostname:port:db" password="password" user="user"/>
  </dataSource>

  <jndiEntry id="db" jndiName="database" value="jdbc/XXXX"/>

</server>

When setup this way with the include, it fails (doesn't seem to recognize the datasource). When I put the datasource and jndientry back directly into the server.xml in the exact same spot where I had the include, it works fine.

Yes, Liberty can handle splitting datasources out of the server.xml into it's own file and then included via <include /> , that's true for any config element.

I don't see anything wrong in your configuration, so it might be the file location or name not being correct. I'd recommend checking your log to make sure you don't see CWWKG0090E which would indicate that the server.xml can't find/resolve your include file.

Yes, you can put Liberty data sources (dataSource element) into include files and reference the include file from server.xml, just as shown in your example. It works great for me, so possibly there is some subtle difference in your file structure/file names? I'd recommend double, or triple checking everything to be sure. You are using a relative location ${server.config.dir} which means your datasources-join-include.xml file should be in the same folder as your server.xml, and should have that exact name.

If it's still not working for you, here is something that might be helpful in debugging. A Liberty blog post describes a couple of Liberty REST endpoints, one of which shows you a merged view of configuration. In your case, after configuring the necessary features described in the blog post to make the REST endpoint available, give this a try and see if it is recognizing the configuration of your dataSource,

https://localhost:9443/ibm/api/config/dataSource

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM