0
 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<context:component-scan base-package="com.example.hibernate" />

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/emp" />
        <property name="username" value="root" />
        <property name="password" value="admin" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" autowire = "byname">
        <property name="dataSource" ref="myDataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
                </prop>
                <prop key="hibernate.connection.pool_size">20</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>Departments.hbm.xml</value>
            </list>
        </property>
    </bean>
    <bean id ="employeeDAO" class = "com.example.hibernate.dao.EmployeeDAOImpl" autowire = "byname"/>
</beans>

そしてこちらがMflow

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"
    xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
    xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<spring:beans>
        <spring:import resource="DBConfigurations.xml" />
    </spring:beans>

    <data-mapper:config name="getEmployeeDetailsReq"
        transformationGraphPath="getEmployeeDetailsReq.grf" doc:name="getEmployeeDetailsReq" />
    <data-mapper:config name="getEmployeeDetailsResponse" transformationGraphPath="getEmployeeDetailsResponse.grf" doc:name="getEmployeeDetailsResponse"/>

    <flow name="EmployeeDetailsFlow" doc:name="EmployeeDetailsFlow">
        <http:inbound-endpoint exchange-pattern="request-response"
            address="http://localhost:9090/getEmployeeDetails" doc:name="Receive" />
        <object-to-string-transformer doc:name="Object to String" />
        <data-mapper:transform config-ref="getEmployeeDetailsReq"
            doc:name="getEmployeeDetailsReq" />
        <component doc:name="GetTemplateInfo"
            class="com.example.hibernate.dao.GetEmployeeDetails" />
        <data-mapper:transform config-ref="getEmployeeDetailsResponse" returnClass="java.lang.String" doc:name="getEmployeeDetailsResponse"/>
        <json:object-to-json-transformer
            doc:name="Object to JSON" />
    </flow>

</mule>

これが私のJavaコンポーネントです

package com.example.hibernate.dao;

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.example.hibernate.Employee;

public class GetEmployeeDetails  implements Callable{

    @Autowired
    @Qualifier("employeeDAO")
    private EmployeeDAO dao;
    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        Employee emp = (Employee)eventContext.getMessage().getPayload();
        return dao.getEmployeeDetailsById(emp.getId());
    }

}

オートワイヤーとスプリングセッター注入を使用してオブジェクトを注入しようとしました。コンストラクターとセッター メソッドに Syso を追加することによる両方のシナリオで、アプリケーションの起動時にオブジェクトが挿入されることに気付きました。sysos がコンソールに表示されます。

リクエストを送信すると、オブジェクトが null になり、NullPointerException をスローして失敗します。
Service クラスでも同じことは機能しません。

誰でも私を助けることができますか?

前もって感謝します。

4

1 に答える 1