title: Add Spring boot into my spring mvc hibernate application
body: <p>I would like to migrate  my <code>spring mvc hibernate configuration</code> into
  <code>spring boot</code>.
  I am attaching my configuration file which is used to <code>beans configuration</code>. But i want to play with Spring boot.  Please help me to migrate my application in Spring boot .</p>
  
  <p><strong>Config.java</strong></p>
  
  <pre><code>import java.util.Properties;
  
  import javax.annotation.Resource;
  
  import org.apache.commons.dbcp2.BasicDataSource;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
  import org.springframework.context.support.ReloadableResourceBundleMessageSource;
  import org.springframework.core.env.Environment;
  import org.springframework.orm.hibernate4.HibernateTransactionManager;
  import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  import org.springframework.web.multipart.commons.CommonsMultipartResolver;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  import org.springframework.web.servlet.view.InternalResourceViewResolver;
  import org.springframework.web.servlet.view.XmlViewResolver;
  import org.thymeleaf.spring4.SpringTemplateEngine;
  import org.thymeleaf.spring4.view.ThymeleafViewResolver;
  import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
  import org.thymeleaf.templateresolver.TemplateResolver;
  
  @Configuration
  @ComponentScan("")
  @EnableWebMvc
  @EnableTransactionManagement
  @PropertySource("classpath:application.properties")
  public class Config extends WebMvcConfigurerAdapter {
  
      @Value("${db.driver}")
      private String dbDriver;
  
      @Value("${db.url}")
      private String dbUrl;
  
      @Value("${db.username}")
      private String dbUserName;
  
      @Value("${db.password}")
      private String dbPassword;
  
      @Value("${hibernate.dialect}")
      private String dialect;
  
      @Value("${hibernate.hbm2ddl.auto}")
      private String hbmddl;
  
      @Value("${message.basename}")
      private String baseName;
  
      @Value("${message.encoding}")
      private String encoding;
  
      @Value("${hibernate.connection.datasource}")
      private String datasource;
  
      @Resource
      private Environment environment;
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
      }
  
      public XmlViewResolver XmlViewResolver() {
  
          XmlViewResolver xmlViewResolver = new XmlViewResolver();
          return xmlViewResolver;
      }
  
      @Bean
      public InternalResourceViewResolver setupViewResolverForRedirect() {
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
  
          resolver.setViewNames(new String[] { "redirect*" });
          return resolver;
      }
  
      @Bean
      public CommonsMultipartResolver multipartResolver() {
          CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
          // commonsMultipartResolver.setMaxUploadSize(1048576);
          commonsMultipartResolver.setMaxUploadSize(10000000);
          return commonsMultipartResolver;
      }
  
      @Bean
      public TemplateResolver templateResolver() {
          ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
          templateResolver.setPrefix("/WEB-INF/views/");
          templateResolver.setSuffix(".html");
          templateResolver.setCacheable(false);
          templateResolver.setTemplateMode("HTML5");
  
          return templateResolver;
      }
  
      @Bean
      public SpringTemplateEngine templateEngine() {
          SpringTemplateEngine templateEngine = new SpringTemplateEngine();
          templateEngine.setTemplateResolver(templateResolver());
          return templateEngine;
      }
  
      @Bean
      public ThymeleafViewResolver viewResolver() {
          ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
          viewResolver.setTemplateEngine(templateEngine());
          return viewResolver;
      }
  
      @Bean(name = "messageSource")
      public ReloadableResourceBundleMessageSource getMessageSource() {
          ReloadableResourceBundleMessageSource resource = new ReloadableResourceBundleMessageSource();
  
          resource.setBasename(baseName);
          resource.setDefaultEncoding(encoding);
          return resource;
      }
  
      @Bean
      public SessionFactory getSessionFactory() {
  
          LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(getDataSource());
  
          sessionBuilder.addProperties(getHibernateProperties());
  
          sessionBuilder.addAnnotatedClass(com.aaaa.Example.class);
  
          return sessionBuilder.buildSessionFactory();
      }
  
      private Properties getHibernateProperties() {
          Properties properties = new Properties();
          properties.put("hibernate.show_sql", true);
          properties.put("hibernate.dialect", dialect);
  
          if (datasource!=null &amp;&amp; !datasource.equalsIgnoreCase("")) {
              properties.put("hibernate.connection.datasource",datasource);
          }
  
          properties.put("hibernate.hbm2ddl.auto", hbmddl);
  
  
          return properties;
      }
  
      @Bean
      public BasicDataSource getDataSource() {
          BasicDataSource dataSource = new BasicDataSource();
  
          dataSource.setDriverClassName(dbDriver);
          dataSource.setUrl(dbUrl);
          dataSource.setUsername(dbUserName);
          dataSource.setPassword(dbPassword);
  
          return dataSource;
      }
  
      @Bean
      public HibernateTransactionManager getTransactionManager() {
          HibernateTransactionManager transactionManager = new HibernateTransactionManager(getSessionFactory());
  
          return transactionManager;
      }
  
      @Bean
      public static PropertySourcesPlaceholderConfigurer propertyConfig() {
          return new PropertySourcesPlaceholderConfigurer();
      }
  
  }
  </code></pre>