Odata4J和Spring Autowiring

时间:2013-03-26 14:36:44

标签: spring jersey odata odata4j

我无法将JpaTransactionManager transactionManagerOdata自动连接到Odata ExampleProducerFactory servlet中。

TransactionManagerOdata配置正常,可以在任何其他Spring类中自动连接。

在我的情况下,transactionManagerOdata始终为null。 请问,你有什么建议如何配置Odata4J ExampleProducerFactory,所以Spring知道这个servlet。

谢谢

web.xml

 <servlet>
   <servlet-name>OData</servlet-name>
   <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
   <init-param>
     <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
     <param-value>org.odata4j.jersey.producer.resources.ODataApplication</param-value>
   </init-param>
   <init-param>
   <param-name>odata4j.producerfactory</param-name>
   <param-value>com.sungard.webapp.odata.apex.producer.ExampleProducerFactory</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
   <servlet-name>OData</servlet-name>
   <url-pattern>/example.svc/*</url-pattern>
   </servlet-mapping>

ExampleProducerFactory.java

    @Configurable(autowire= Autowire.BY_NAME)
    public class ExampleProducerFactory   implements ODataProducerFactory   
    {   
    @Autowired(required=true)
    private JpaTransactionManager transactionManagerOdata;  

        public ODataProducer create(Properties properties) 
        {               
    EntityManagerFactory emf = transactionManagerOdata.getEntityManagerFactory();               
    JPAProducer tmpProd = new JPAProducer(emf, "", 500);                
    return tmpProd;     
    }
}

的applicationContext.xml

       <bean class="org.springframework.orm.jpa.JpaTransactionManager"
           id="transactionManagerOdata">                
       <property name="entityManagerFactory" ref="entityManagerFactoryOdata" />
    </bean>
       <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    id="entityManagerFactoryOdata">
    <property name="persistenceUnitName" value="persistenceUnitOdata" />
    <property name="persistenceXmlLocation"
        value="classpath*:META-INF/persistence-spring-odata.xml" />
    <property name="dataSource" ref="dataSource" />
    </bean>

0 个答案:

没有答案