您好我学习春豆,我尝试过这个简单的豆子。我有一个带有数据成员的类。使用setter方法初始化数据成员。我在带有标记的bean配置xml中设置了数据成员。我得到一个空指针异常,重新考虑"消息"我试图传递给二传手。我不认为NULL实际上是通过的,因为我在传递字符串文字时面临同样的问题。
这是我的班级:
public class HelloWorld implements DummyInterface {
//private WebAppPackagerPortal WebAppObj;
private String message;
public void setMessage(String message) {
this.message = message;
}
public String getMessage(){
return this.message;
}
@Override
public void printMessage() {
}
}
这是我的bean xml:
<bean id="HelloWorldBean" class="pkg.HelloWorld">
<property name="message" value="${content.msg}"/>
<!--<property name="message" value="DUMMYMSG"/>-->
</bean>
我得到的例外情况如下:
> Feb 24, 2016 1:33:50 PM org.apache.catalina.core.StandardContext
> listenerStart SEVERE: Exception sending context initialized event to
> listener instance of class
> org.springframework.web.context.ContextLoaderListener
> org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'HelloWorldBean' defined in ServletContext
> resource [/WEB-INF/spring-config.xml]: Error setting property values;
> nested exception is
> org.springframework.beans.PropertyBatchUpdateException; nested
> PropertyAccessExceptions (1) are: PropertyAccessException 1:
> org.springframework.beans.MethodInvocationException: Property
> 'message' threw exception; nested exception is
> java.lang.NullPointerException at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
> at
...
Caused by:
> org.springframework.beans.PropertyBatchUpdateException; nested
> PropertyAccessExceptions (1) are: PropertyAccessException 1:
> org.springframework.beans.MethodInvocationException: Property
> 'message' threw exception; nested exception is
> java.lang.NullPointerException at
> org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
> at
> org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
> at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1510)
> ... 26 more
答案 0 :(得分:1)
您发布的代码没有任何问题。随着春天,问题可能并不总是你认为的问题:)。由于您尚未发布实际用于实例化bean或您使用的弹簧版/罐的代码,我建议您尝试这些步骤。
ApplicationContext applicationContext = new
ClassPathXmlApplicationContext("/spring-config.xml");
HelloWorld helloWorld = (HelloWorld ) applicationContext.getBean("HelloWorldBean");
,看看它是否有效。如果您得到相同的错误,则表示问题出在其他地方。可以在配置中。第二步是尝试在Web容器外运行它。
<div class="booking-wrap-horz cf"> <div class="bookingform cf">
<form class="b-form" action="nextpage.html" id="myform" method="post" target="_blank">
<div class="arrival group">
<input type="text" name="A" id="arrive" class="datepicker required" placeholder="ARRIVE"></div>
<div class="departure group">
<input type="text" name="D" id="depart" class="datepicker required" placeholder="DEPART">
</div>
<div class="adults group">
<select name="Ad" id="adults" class="dk">
<option selected disabled>adults</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
<div class="bookbtn group">
<button type="submit" value="Submit" id="submit" class="booksub">Book Now</button>
</div>
</form>
</div></div>
如果可行,则查看Web应用程序配置,并将生成的Web应用程序中的jar与构建环境进行比较。
org.springframework.beans.PropertyBatchUpdateException;嵌套...
有时,不兼容的罐子会导致这个问题,但并非总是如此。