1
我是新來的Java,Spring和規劃環境地政司,我不能讓這個簡單的代碼工作(它的工作原理沒有評估進口THO)春規劃環境地政司錯誤
這是我的課RunSpring.java:
package run;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import helloworld.HelloSpringWorld;
public class RunSpring
{
public static void main(String[] args)
{
//App Context
ApplicationContext appContext = new ClassPathXmlApplicationContext("bean-data.xml");
BeanFactory beanFactory = appContext;
HelloSpringWorld instance = (HelloSpringWorld);
beanFactory.getBean("helloSpringWorld");
//Expression to be evaluated
instance.greeting("${5+5}");
}
}
這是我的類HelloSpringWorld:
package helloworld;
import org.springframework.stereotype.Service;
//Expression imports
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
@Service
public class HelloSpringWorld
{
public void greeting(String name)
{
//Expression Setup
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(name);
String message = (String) exp.getValue();
System.out.println("Hello and welcome to Spring: " + message);
}
}
錯誤:解析有效表達後,有在表達式仍然更多數據: 'lcurly({)'
任何提示?
謝謝你的時間。
任何運氣這樣的:
然後打電話? –
其實它應該是'parser.parseExpression(name)':) –
@kocko謝謝你的指出。這是從我做的測試中遺留下來的。 –