Moving from Spring MVC XML files to javaconfig. I am really at a lost with my database XML file

后端 未结 1 802
挽巷
挽巷 2021-02-02 03:57

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

相关标签:
1条回答
  • 2021-02-02 04:28

    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;
    }
    
    0 讨论(0)
提交回复
热议问题