私は春が初めてで、春のバージョン 3.2.2 を使用しています。スプリング式言語 (SPEL) を使用していくつかの例を作成しようとしました。しかし、春の構成ファイルで論理演算子を使用しているときに問題に直面しています。
以下のスプリング構成ファイルのスニペットを見つけてください。
<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-3.0.xsd">
<bean id="bean3" class="com.springaction.testcollection.PersonBean">
<property name="name" value="Prakash" />
<property name="age" value="62" />
<property name="salary" value="30000" />
<property name="bonus" value="#{30000*T(com.springaction.testcollection.PersonBean).count}" />
</bean>
<bean id="bean4" class="com.springaction.testcollection.PersonBean">
<property name="name" value="Kamini" />
<property name="age" value="60" />
<property name="manager" value="#{bean3.name=='Jinesh' or (bean3.salary -gt 3000 and bean3.age -le 62)}" />
</bean>
</beans>
以下の PersonBean.java ファイルを参考にしてください。
/**
*
*/
package com.springaction.testcollection;
import org.springframework.beans.factory.InitializingBean;
/**
* @author jinesh
*
*/
public class PersonBean implements InitializingBean{
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
String name;
int age;
Float salary;
public static int count=1;
Float bonus;
boolean manager;
PersonBean(){
// System.out.println("******** Constructor gets called ************");
count++;
}
/**
* @return the manager
*/
public boolean isManager() {
return manager;
}
/**
* @param manager the manager to set
*/
public void setManager(boolean manager) {
this.manager = manager;
}
/**
* @return the bonus
*/
public Float getBonus() {
return bonus;
}
/**
* @param bonus the bonus to set
*/
public void setBonus(Float bonus) {
this.bonus = bonus;
}
/**
* @return the count
*/
public static int getCount() {
return count;
}
/**
* @param count the count to set
*/
public static void setCount(int count) {
PersonBean.count = count;
}
/**
* @return the salary
*/
public Float getSalary() {
return salary;
}
/**
* @param salary the salary to set
*/
public void setSalary(Float salary) {
this.salary = salary;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
//System.out.println("***** Setter method of the name gets called **********");
this.name = name;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
//System.out.println("***** Setter method of the age gets called **********");
this.age = age;
}
}
以下のコードを使用して bean4 を取得しようとすると、例外が発生します。
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.springaction.testcollection.PersonBean;
import com.springaction.testmap.PersonBeanMap;
/**
* @author jinesh
*
*/
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("talentacquisition.xml");
PersonBean pbb3=(PersonBean)context.getBean("bean4");
System.out.println(pbb3.isManager());
}
}
以下は、上記のメイン アプリケーション コードの実行中に発生する例外です。
原因: org.springframework.expression.spel.SpelParseException: EL1043E:(pos 42): 予期しないトークン。「rparen())」が必要でしたが、「literal_int」でした
spring 構成ファイルに記載されているように、括弧を使用して複数の論理式を組み合わせることはできませんか? いいえの場合、誰かが私に正しい方法を提案できますか?