4

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

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

在我的情况下 transactionManagerOdata 始终为空。请问,您对如何配置 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;     
    }
}

应用程序上下文.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>
4

0 回答 0