title: SpringBoot : Setting DataSource "jmx-enabled" is not registering the Datasource
body: <p>I am trying to add my data source to JMX by setting the property "jmx-enabled" to true. I have two data sources, therefore the configuration properties are a little different: </p>
  
  <pre><code>datasource:
    main:
      driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
      url: jdbc:sqlserver://chico-testdb1.build.internal\CHICOTEST;selectMethod=cursor;applicationName=omc;sendStringParametersAsUnicode=false
      username: *
      password: *
      max-active: 150
      jmx-enabled: true
  </code></pre>
  
  <p>I looked at the DataSourceAutoConfiguration class and it appears to only create the MBean when the configuration uses the "spring.datasource" prefix. So I modeled my own configuration after this example: </p>
  
  <pre><code>    @Bean
      @ConditionalOnProperty(prefix = "datasource.main", name = "jmx-enabled", havingValue="true")
      public Object dataSourceMBean(@Qualifier("mainDataSource") DataSource dataSource) {
          if (dataSource instanceof DataSourceProxy) {
              try {
                  return ((DataSourceProxy) dataSource).createPool().getJmxPool();
              }
              catch (SQLException ex) {
                  logger.warn("Cannot expose DataSource to JMX (could not connect)");
              }
          }
          return null;
      }
  </code></pre>
  
  <p>The condition is working perfectly and this method is returning the Jmx connection pool. However, this bean is still not getting registered with the MBeanServer and I am seeing no exceptions in the logs.</p>
  
  <p>I have been able to work around this by explicitly registering the bean with the server but this but I feel like there should be a better way? </p>
  
  <pre><code>    @Bean
      @ConditionalOnProperty(prefix = "datasource.main", name = "jmx-enabled", havingValue="true")
      public ConnectionPool getJmxPool(@Qualifier("mainDataSource") DataSource dataSource, MBeanServer mBeanServer) throws SQLException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException {
          if (dataSource instanceof DataSourceProxy) {
              ConnectionPool pool = ((DataSourceProxy)dataSource).createPool().getJmxPool();
              mBeanServer.registerMBean(pool, new ObjectName("com.build.jdbc:type="+ dataSource.getClass().getName()+",name=main"));
              return pool;
          }
          return null;
      }
  </code></pre>