title: PhysicalNamingStrategy bean only instantiates via config file
body: <p>I have a custom naming strategy in a Spring app with Hibernate:</p>
  
  <pre><code>public class MyCustomPhysicalNamingStrategy implements PhysicalNamingStrategy {
  
    @Override
    public Identifier toPhysicalTableName(Identifier identifier, JdbcEnvironment jdbcEnvironment) {
      return Identifier.toIdentifier("my_custom_table_name");
    }
  
    // ...
  
  }
  </code></pre>
  
  <p><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html#howto-configure-hibernate-naming-strategy" rel="nofollow noreferrer">The Spring documentation</a> says I can tell Hibernate to use it either by setting <code>spring.jpa.hibernate.naming.physical-strategy</code> (which works fine), or like this:</p>
  
  <blockquote>
    <p>Alternatively, if <code>ImplicitNamingStrategy</code> or <code>PhysicalNamingStrategy</code> beans are available in the application context, Hibernate will be automatically configured to use them</p>
  </blockquote>
  
  <p>I need to use this second method, as I need to pass some info from Spring's context to my naming strategy. However, I can't get it to work.</p>
  
  <p>I'm creating the bean in the following configuration class:</p>
  
  <pre><code>@Configuration
  public class PersistenceConfiguration {
    @Bean
    public PhysicalNamingStrategy physicalNamingStrategy() {
      return new MyCustomPhysicalNamingStrategy();
    }
  }
  </code></pre>
  
  <p>What am I missing here? </p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT:</strong> I'm on Spring Boot/Spring JPA 1.5.9.RELEASE, which gives me Hibernate core v.5.0.12.Final and Hibernate JPA API 2.1.</p>