title: Moving from Spring MVC XML files to javaconfig. I am really at a lost with my database XML file
body: <p>I Moving from Spring MVC XML files to javaconfig. I am really at a lost with my database XML file. I don't know how to get Hibernate4 working and my JBoss JNDI Datasource working.  Can someone please tell me how to make the javaconfig class work like this XML..</p>
  
  <p>Here is my database.xml:</p>
  
  <pre><code>?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
      xmlns:jee="http://www.springframework.org/schema/jee"
  
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                              http://www.springframework.org/schema/beans/spring-beans.xsd
                              http://www.springframework.org/schema/context
                              http://www.springframework.org/schema/context/spring-context-3.1.xsd
                              http://www.springframework.org/schema/tx
                              http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                              http://www.springframework.org/schema/jdbc
                              http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                              http://www.springframework.org/schema/jee
                              http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"&gt;
  
  
      &lt;context:property-placeholder location="classpath:app.properties" /&gt;
  
      &lt;context:component-scan base-package="org.uftwf" /&gt;
  
      &lt;tx:annotation-driven transaction-manager="hibernateTransactionManager" /&gt;
  
      &lt;jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/mySQLDB"
          expected-type="javax.sql.DataSource" /&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;org.uftwf.inquiry.model.MemberInquiryInformation&lt;/value&gt;
  
              &lt;/list&gt;
          &lt;/property&gt;
  
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
                  &lt;prop key="hibernate.use_sql_comments"&gt;${hibernate.use_sql_comments}&lt;/prop&gt;
                  &lt;prop key="format_sql"&gt;${format_sql}&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="hibernateTransactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Here is my javaconfig class:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages= {"org.uftwf.inquiry"})
  @ImportResource("/WEB-INF/spring/root-config.xml")
  public class WebMVCConfig extends WebMvcConfigurerAdapter {
  
      private static final String MESSAGE_SOURCE = "/WEB-INF/classes/messages";
  
      private static final Logger logger = LoggerFactory.getLogger(WebMVCConfig.class);
  
  
      @Value("${jdbc.driverClassName}")
      private String driverClassName;
  
      @Value("${jdbc.url}")
      private String url;
  
      @Value("${jdbc.username}")
      private String username;
  
      @Value("${jdbc.password}")
      private String password;
  
      @Value("${hibernate.dialect}")
      private String hibernateDialect;
  
      @Value("${hibernate.show_sql}")
      private String hibernateShowSql;
  
      @Value("${hibernate.hbm2ddl.auto}")
      private String hibernateHbm2ddlAuto;
  
      @Bean
      public PropertyPlaceholderConfigurer getPropertyPlaceholderConfigurer()
      {
          PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
          ppc.setLocation(new ClassPathResource("application.properties"));
          ppc.setIgnoreUnresolvablePlaceholders(true);
          return ppc;
      }
  
      @Bean()
      public DataSource getDataSource()
      {
          DriverManagerDataSource ds = new DriverManagerDataSource();
          ds.setDriverClassName(driverClassName);
          ds.setUrl(url);
          ds.setUsername(username);
          ds.setPassword(password);
          return ds;
      }
  
      @Bean
      public LocalSessionFactoryBean sessionFactory()
      {
  
          LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
          factoryBean.setDataSource(getDataSource());
          factoryBean.setHibernateProperties(getHibernateProperties());
          factoryBean.setPackagesToScan("org.uftwf.inquiry.model");
  
          return factoryBean;
      }
  
      @Bean
      public Properties getHibernateProperties()
      {
          Properties hibernateProperties = new Properties();
  
          hibernateProperties.setProperty("hibernate.dialect",  hibernateDialect);
          //hibernateProperties.setProperty("hibernate.show_sql", "true");
          //hibernateProperties.setProperty("hibernate.format_sql", "true");
          hibernateProperties.setProperty("hibernate.hbm2ddl.auto", "update");
          hibernateProperties.setProperty("javax.persistence.validation.mode", "none");
  
          //Audit History flags
          hibernateProperties.setProperty("org.hibernate.envers.store_data_at_delete", "true");
          hibernateProperties.setProperty("org.hibernate.envers.global_with_modified_flag", "true");
  
          return hibernateProperties;
      }
  
      @Bean
      @Autowired
      public HibernateTransactionManager transactionManager(SessionFactory sessionFactory)
      {
          HibernateTransactionManager htm = new HibernateTransactionManager();
          htm.setSessionFactory(sessionFactory);
          return htm;
      }
  
      @Bean
      public  ViewResolver resolver() {
          UrlBasedViewResolver url = new UrlBasedViewResolver();
          url.setPrefix("/WEB-INF/view/");
          url.setViewClass(JstlView.class);
          url.setSuffix(".jsp");
          return url;
      }
  
  
      @Bean(name = "messageSource")
      public MessageSource configureMessageSource() {
          logger.debug("setting up message source");
          ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
          messageSource.setBasename(MESSAGE_SOURCE);
          messageSource.setCacheSeconds(5);
          messageSource.setDefaultEncoding("UTF-8");
          return messageSource;
      }
  
      @Bean
      public LocaleResolver localeResolver() {
          SessionLocaleResolver lr = new SessionLocaleResolver();
          lr.setDefaultLocale(Locale.ENGLISH);
          return lr;
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          logger.debug("setting up resource handlers");
          registry.addResourceHandler("/resources/").addResourceLocations("/resources/**");
      }
  
      @Override
      public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
          logger.debug("configureDefaultServletHandling");
          configurer.enable();
      }
  
      @Override
      public void addInterceptors(final InterceptorRegistry registry) {
          registry.addInterceptor(new LocaleChangeInterceptor());
      }
  
      @Bean
      public SimpleMappingExceptionResolver simpleMappingExceptionResolver() {
          SimpleMappingExceptionResolver b = new SimpleMappingExceptionResolver();
  
          Properties mappings = new Properties();
          mappings.put("org.springframework.web.servlet.PageNotFound", "p404");
          mappings.put("org.springframework.dao.DataAccessException", "dataAccessFailure");
          mappings.put("org.springframework.transaction.TransactionException", "dataAccessFailure");
          b.setExceptionMappings(mappings);
          return b;
      }
  
      @Bean
      public RequestTrackerConfig requestTrackerConfig()
      {
          RequestTrackerConfig tr = new RequestTrackerConfig();
          tr.setPassword("Waiting#$");
          tr.setUrl("https://uftwfrt01-dev.uftmasterad.org/REST/1.0");
          tr.setUser("root");
  
          return tr;
      }
  
  
  }
  </code></pre>
  
  <p>I think the parts I am missing are the following but please overcheck my class</p>
  
  <pre><code>&lt;context:property-placeholder location="classpath:app.properties" /&gt;
  
      &lt;context:component-scan base-package="org.uftwf" /&gt;
  
      &lt;tx:annotation-driven transaction-manager="hibernateTransactionManager" /&gt;
  
      &lt;jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/mySQLDB"
          expected-type="javax.sql.DataSource" /&gt;
  </code></pre>