0

I am in the middle of converting my appconfig.xml tp JavaConfigurations(AnnotationConfigs). I did converting most of the beans into JavaConfig. But I am got stuck with couple of beans which are listed below. Could some one help me on this..??

1.The Bean has a list element which takes values from a properties file.. The XML Configuration is :

<bean id="propertyCommons"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:dbUser.properties</value>
            </list>
        </property>
        <property name="ignoreUnresolvablePlaceholders" value="true" />
    </bean>

How do we convert this to java Config..(especially taking values from dbUser.properties?

2.How do we convert the following factory configuration to JavaConfigs?

    .
    .
    .
    <bean id="oozieJobFactoryBean" class="com.mycompany.product.dfe.main.OozieJobFactoryBean" />

    <bean id="cmdArgs" class="com.mycompany.product.dfe.main.CmdArgs"
            scope="prototype" />

    <bean id="oozieJob" factory-bean="oozieJobFactoryBean"
            factory-method="createJob" scope="prototype">
            <constructor-arg ref="cmdArgs" />
    </bean>
    .
    .
    .

3. Also the following Configuration ..

.
.
.
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="productPU" />
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.cache.use_second_level_cache" value="true" />
            <entry key="hibernate.cache.use_query_cache" value="true" />
            <entry key="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" />
            <entry key="hibernate.show_sql" value="false" />
            <entry key="hibernate.format_sql" value="false" />
            <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <entry key="javax.persistence.validation.mode" value="NONE" />
            <entry key="hibernate.connection.characterEncoding" value="utf8" />
        </map>
    </property>
</bean>
.
.
.

Please help me on this am new to spring.. :) Thanks in Advance...

Noushad Ali.

1 Answer 1

1

1.PropertyPlaceholderConfigurer

@Configuration
@PropertySource(value = "spring/test5.properties")
class Config {
    @Bean
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
        c.setIgnoreUnresolvablePlaceholders(true);
        return c;
    }

...
  1. OOzieJobFactory

    class Config {

    @Bean
    @Scope("prototype")
    CmdArgs cmdArgs() {
        return new CmdArgs();
    }
    
    @Bean
    @Scope("prototype")
    OozieJobFactory oozieJobFactory() {
        return new OozieJobFactory();
    }
    
    @Bean
    OozieJob oozieJob(OozieJobFactory factory, CmdArgs cmdArgs) {
        return factory.createJob(cmdArgs);
    }
    

    }

  2. EntityManager

    class Config {

    @Bean
    LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
        LocalContainerEntityManagerFactoryBean b = new LocalContainerEntityManagerFactoryBean();
        b.setPersistenceUnitName("productPU");
        ...
        return b;
    }
    
    @Bean
    JpaTransactionManager jpaTransactionManager(LocalContainerEntityManagerFactoryBean emf) {
        JpaTransactionManager tm = new JpaTransactionManager();
        tm.setEntityManagerFactory(emf);
        return tm;
    }
    
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @Evgeniy Dorofeev, Can you help me on my second and third question..?
Phew, code in enumerated lists really is getting ugly. I remember a Meta question about how to fix this.
I think it is tm.setEntityManagerFactory(emf.getObject());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.