title: Convert existing Spring application to Spring-Boot
body: <p>I have configured and working Spring-based REST application, but now I'd like to convert it to Spring-Boot. </p>
  
  <p>My application uses Spring-Data-JPA on top of JPA datasource with Hibernate provider:</p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories("foo.bar.web.repository")
  @EnableTransactionManagement
  public class RepositoryConfig {
  
      // properties ommited
  
      @Bean
      public DataSource dataSource() {
          BasicDataSource dataSource = new BasicDataSource();
          dataSource.setDriverClassName(className);
          dataSource.setUrl(url);
          dataSource.setUsername(userName);
          dataSource.setPassword(password);
          return dataSource;
      }
  
      @Bean
      public EntityManagerFactory entityManagerFactory() {
          LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
          factory.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
          factory.setPackagesToScan("foo.bar.web.domain");
          factory.setDataSource(dataSource());
          factory.setJpaPropertyMap(new HashMap&lt;String, Object&gt;() {{
              put("hibernate.dialect", dialect);
              put("hibernate.hbm2ddl.auto", hbm2ddl);
          }});
          factory.afterPropertiesSet();
          return factory.getObject();
      }
  
      @Bean
      public PlatformTransactionManager transactionManager() {
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(entityManagerFactory());
          return transactionManager;
      }
  }
  </code></pre>
  
  <p>My REST endpoints implemented using SpringMVC with following configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan("foo.bar.web.controller")
  public class MvcConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
          configurer.enable();
      }
  
      @Bean
      public MultipartResolver multipartResolver() {
          return new CommonsMultipartResolver();
      }
  }
  </code></pre>
  
  <p>Web initializer:</p>
  
  <pre><code>public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class[]{
                  ApplicationConfig.class,
                  RepositoryConfig.class
          };
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class[]{MvcConfig.class};
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[]{"/"};
      }
  }
  </code></pre>
  
  <p>The problem is that I don't want to use Spring-Boot auto configuration because I'd like to reuse my existing configuration classes with minimal changes, but I cannot find correct way to do this. I tried to implement Spring-boot application class annotated with <code>@SpringBootApplication</code>, but I'm not 100% sure that my config classes is used, because in this case I get <code>java.lang.ClassCastException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean$$EnhancerBySpringCGLIB$$ba21071f cannot be cast to javax.persistence.EntityManagerFactory</code>.</p>
  
  <p>Also I tried throw away @EnableAutoConfiguration annotation from application class and add <code>TomcatEmbeddedServletContainerFactory</code> bean to my context manually, but in this case the embedded tomcat is not configured properly.</p>
  
  <p>It would be great if somebody can give me a hint how to solve my problem. I believe that all I need to do is somehow replace my WebInitilizer with Spring-Boot config.</p>