Spring无法实例化bean

时间:2015-10-01 09:30:27

标签: spring web-services rest jpa jersey

我使用Jersey 1.14实现开发了RESTful Web服务。我使用Spring 3.0.6.RELEASE来加载webservice。 webservice接受json输入并使用DAO使用JPA更新数据库。

当客户端类成功调用RLWebService时,它无法获取RLServiceDao的实例。 WebService和DAO类都具有相关属性和getter / setter。

以下是我的applicationContext.xml

<bean id="applicationContextProvider" class="com.clsa.gcp.cms.server.ws.rlwebservice.AppInitializer"></bean>

<bean id="rlServiceDAO" class="com.server.dao.RLServiceDAO">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="rlWebService" class="com.server.ws.rlwebservice.RLWebService">
    <property name="rlServiceDAO" ref="rlServiceDAO" />
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    p:dataSource-ref="cmsdataSource">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="${jdbc.database}" />
            <property name="showSql" value="${jdbc.showSql}" />
        </bean>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.connection.show_sql">${hibernate.show_sql}</prop>
            <!--  prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop-->
            <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
            <prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>
            <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
            <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
            <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
            <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
            <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
            <prop key="hibernate.use_outer_join">${hibernate.use_outer_join}</prop>
            <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
        </props>
    </property>
</bean>`

我编写了一个调用此Web服务的简单客户端类:

HttpURLConnection connection = null;
try {
    URL url = new URL("http://127.0.0.1:8888/gcpcms/api/rlservice");

    connection = (HttpURLConnection)url.openConnection();
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setConnectTimeout(600000);
    connection.setReadTimeout(600000);
    OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
    out.write(jsonObject.toString());
    out.flush();
    out.close();

    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

    String output;

    while ((output = in.readLine()) != null) {
        System.out.println(output);
    }
    System.out.println("RLService REST Service Invoked Successfully..");
    in.close();
} catch (Exception e) {
    System.out.println("\nError while calling RLService REST Service");
    System.out.println(e);
} finally {
    connection.disconnect();
}

0 个答案:

没有答案