如何为这个 XML 配置写 Java 配置。?

How Write Java Configuration for this XML configuration.?

我正在转换我的 appconfig.xml tp JavaConfigurations(AnnotationConfigs)。我确实将大部分 bean 转换为 JavaConfig。但是我被下面列出的几个豆子困住了。有人可以帮我解决这个问题吗??

1.The Bean 有一个列表元素,它从属性文件中获取值。 XML配置为:

<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>

我们如何将其转换为 java 配置..(特别是从 dbUser.properties?

获取值

2.How 我们是否将以下工厂配置转换为 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。还有下面的配置..

.
.
.
<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>
.
.
.

请帮我解决这个 spring.. 的新问题。:) 提前致谢...

努沙德·阿里。

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 配置 {

    @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. 实体管理器

    class 配置 {

    @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;
    }