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 worki
For
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />
annotate your Configuration class, WebMVCConfig
, with
@EnableTransactionManagement
For
<context:component-scan base-package="org.uftwf" />
Add the package String to your @ComponentScan
field basePackages
For
<context:property-placeholder location="classpath:app.properties" />
annotate your Configuration class with
@PropertySource(value = "classpath:app.properties")
and make your PropertyPlaceholderConfigurer
@Bean
method static
.
For
<jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/mySQLDB"
expected-type="javax.sql.DataSource" />
I think you can do
@Bean
public DataSource dataSource() throws Exception {
Context ctx = new InitialContext();
return (DataSource) ctx.lookup("java:jboss/datasources/mySQLDB");
}
Instead of autowiring your session factory, just call your @Bean
method
@Bean
public HibernateTransactionManager transactionManager()
{
HibernateTransactionManager htm = new HibernateTransactionManager();
htm.setSessionFactory(sessionFactory());
return htm;
}