Giter Site home page Giter Site logo

Configuration properties cannot be bound to DruidDataSource when the environment contains a non-enumerable property source about spring-boot HOT 4 CLOSED

iQiFengLe avatar iQiFengLe commented on April 28, 2024
Configuration properties cannot be bound to DruidDataSource when the environment contains a non-enumerable property source

from spring-boot.

Comments (4)

wilkinsona avatar wilkinsona commented on April 28, 2024

This is quite similar to #38514 which the underlying cause being the same non-enumerable property source that comes from JNDI being available. You can work around the problem by adding a spring.properties file to src/main/resources that contains spring.jndi.ignore=true.

The failure's occurring because DruidDataSource isn't entirely compatible with configuration property binding.

When all property sources are enumerable, binding can be optimised to only try to bind properties that are present in the environment. For example, if there are no spring.datasource.log.connection.* properties in the environment, the binder will never need to call getConnection() on the DruidDataSource.

When there's a non-enumerable property source in the environment, the binder does not know all of the properties that are available so it has to try to bind everything. As part of trying to bind everything, the binder's calling getConnection() so that it can then introspect its result for setter methods and determine which properties need to be bound to it. This call fails as it's happening before the URL had been set. Even if the URL had been set, the call would still be unwanted as it would leak a connection.

Hopefully the workaround above is enough to get you past the problem. I'll leave this open for now as I'm not sure what, if anything, we can do to address it. One option would be to provide a way to indicate properties that should be ignored when binding to a third-party class. Another would be for you to bind properties to a safe class of your own and then use Boot's PropertyMapper to apply those to the DruidDataSource instance. Lastly, you could explore binding properties to Boot's DataSourceProperties class and then building the DataSource from those properties:

 properties.initializeDataSourceBuilder().type(DruidDataSource.class).build();

from spring-boot.

quaff avatar quaff commented on April 28, 2024

I know it's risky, but can we ignore JndiPropertySource by default since it's vulnerable and not much useful in practice?

from spring-boot.

quaff avatar quaff commented on April 28, 2024

I requested Spring Framework team to disable JndiPropertySource by default. see spring-projects/spring-framework#18598 (comment)

from spring-boot.

philwebb avatar philwebb commented on April 28, 2024

We've opened #39932 to deal with the Jetty JNDI issue. Once that has been done this issue is effectively a duplicate of #34616

from spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.