我想我的第一个春天项目,必须做一些非常愚蠢的,因为我无法弄清楚如何让下面的代码片段的简单工作:基本春天帮助
这里是我的定义文件:
<?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.xsd">
<bean id="AWSProperties" class="com.addy.server.queue.AWSProperties" scope="singleton">
<property name="awsAccessKey" value="test1"/>
<property name="awsSecretKey" value="test2"/>
<property name="awsSQSQueueName" value="testqueue"/>
</bean>
<bean id="QueueService" class="com.addy.server.queue.QueueService">
<constructor-arg ref="AWSProperties"/>
</bean>
</beans>
和我的两个简单豆:
public class AWSProperties {
private String awsAccessKey;
private String awsSecretKey;
private String awsSQSQueueName;
public void setAwsAccessKey(String awsAccessKey) {
awsAccessKey = awsAccessKey;
}
public String getAwsAccessKey() {
return awsAccessKey;
}
public void setAwsSecretKey(String awsSecretKey) {
awsSecretKey = awsSecretKey;
}
public String getAwsSecretKey() {
return awsSecretKey;
}
public void setAwsSQSQueueName(String awsSQSQueueName) {
awsSQSQueueName = awsSQSQueueName;
}
public String getAwsSQSQueueName() {
return awsSQSQueueName;
}
}
public class QueueService {
private AWSProperties properties;
public QueueService(AWSProperties properties)
{
this.properties = properties;
}
public void receiveMessage()
{
System.out.println(properties.getAwsAccessKey());
}
}
当我运行下面的代码片段,我得到“空”时,我期待“测试1”
public class VMMConsumer {
public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"VMMConsumer.xml"});
QueueService service = (QueueService)context.getBean("QueueService");
service.receiveMessage();
}
}
如果你能解释你遇到的问题的确切性质,这可能会有所帮助。汇编?告诉我们错误。值不正确?告诉我们他们是什么......等等。 – AAA 2009-02-07 00:13:10
正如我所指出的,我得到的是null值而不是test1值,但在我的问题中看到我的回答在 – Ish 2009-02-07 00:14:53