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

后端 未结 1 807
挽巷
挽巷 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

    
    

    annotate your Configuration class, WebMVCConfig, with

    @EnableTransactionManagement
    

    For

    
    

    Add the package String to your @ComponentScan field basePackages

    For

    
    

    annotate your Configuration class with

    @PropertySource(value = "classpath:app.properties")
    

    and make your PropertyPlaceholderConfigurer @Bean method static.

    For

     
    

    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)
提交回复
热议问题