无法通过SpEL从sprigconfiguration.xml中的bean中的方法获取值

时间:2019-02-08 09:41:36

标签: java spring

我有一个关于从方法中获取价值的问题。我总是在yazarBean中属性的null中获得bilgi的值。我确定此属性中的yazarBean.adyazarBean.soyad已正确定义。

我也可以分享下面显示的方法。如何从调用函数中获取正确的值。

Spring配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

    <bean id="kitapBean" class="com.a.Kitap">
        <property name="kitapAd" value="İstanbul Hatırası"></property>
        <property name="kitapISBN" value="1234567890"></property>
    </bean>

    <bean id="yazarBean" class="com.a.Yazar">
        <property name="ad" value="Ahmet"></property>
        <property name="soyad" value="Ümit"></property>

        <property name="kitapAd" value="#{kitapBean.kitapAd}"></property>
        <!--  <property name="kitapAd" ref="kitapBean.kitapAd"></property>-->

        <property name="kitap" value="#{kitapBean}"></property> 
        <!--  <property name="kitap" ref="kitapBean"></property> -->


        <!--  <property name="bilgi" value="#{kitapBean.kitapBilgisiGoster('Fyodor','Dostoyevski','Cinler',0987654321)}"></property>-->
        <property name="bilgi" value="#{kitapBean.kitapBilgisiGoster(yazarBean.ad,yazarBean.soyad,kitapBean.kitapAd,kitapBean.kitapISBN)}"></property>
    </bean>

</beans>

kitapBilgisiGoster函数

public String kitapBilgisiGoster(String yazarAd,String yazarSoyad, String kitapAd,long kitapISBN) {

        this.kitapAd = kitapAd;
        this.kitapISBN = kitapISBN;

        String sonuc = "Yazar Ad : " + yazarAd + ""
                      +"\nYazar Soyad : " + yazarSoyad + ""
                      +"\nKitap Ad : " + getKitapAd() 
                      +"\nISBN : " + getKitapISBN();

        return sonuc;
    }

0 个答案:

没有答案