にnullポインタが、私は6.5をZKするZK 5.0から自分のアプリケーションをアップグレードしたとのSpring Beanを再実行適用後のnullの場合、以下のコードがあり、助けてくださいZK +春豆、@Resource
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<description>Application</description>
<display-name>Application</display-name>
<!-- Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config.xml</param-value>
</context-param>
<!-- Spring configuration -->
<!-- Initialize spring context -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- ZK -->
<listener>
<description>ZK listener for cleanup when a session is destroyed</description>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
春-config.xmlの
<?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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.zkoss.org/2008/zkspring/core
http://www.zkoss.org/2008/zkspring/core/zkspring-core.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.dc.myapplication"/>
<context:property-placeholder location="classpath*:settings.properties"/>
<bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/myDB"/>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="jndiDataSource"/>
</bean>
<bean id="settings" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="index.path">${index.path}</prop>
<prop key="max.hits">${max.hits}</prop>
<prop key="search.resultsPerPage">${search.resultsPerPage}</prop>
</props>
</property>
</bean>
</beans>
そして@Componentは CategoryServiceImpl.java以下のように定義されています
0123私はcategoryService.getCategoriesから投げるにNullPointer categoryServiceとを使用する場合についてpackage com.dc.myapplication.service.impl;
import javax.annotation.Resource;
import com.dc.myapplication.domain.RfiCategory;
import com.dc.myapplication.service.CategoryService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
@Component("categoryService")
public class CategoryServiceImpl implements CategoryService {
@Resource JdbcTemplate dataSource;
@Resource CategoryMapper categoryMapper;
@Override
public Iterable<? extends RfiCategory> getCategories() {
return dataSource.query("SELECT * FROM category", categoryMapper);
}
}
がある() SearchController.java
package com.dc.myapplication.controller;
import javax.annotation.Resource;
public class SearchController extends AbstractController implements PaginationListener, RfiCategoryState {
private static final String STATE = "state";
@Resource CategoryService categoryService;
@Override
protected void initialise() {
populateCategories();
}
private void populateCategories() {
for (RfiCategory category : categoryService.getCategories()) {
categories.appendChild(rfiCategoryRenderer.renderRadioSelector(category, this));
}
}
と私は、私が使用している場合、それが動作することがわかっ CategoryService categoryService =(CategoryService)SpringUtil.getBean ( "categoryService"); @Resource CategoryService categoryServiceの代わりに ;
私は古いコードを残したいと思います。誰かが古いコードで何がうまくいかなかったか教えてください。それはzk 5.0で動作していましたか? zkがアップグレードされた後、春のbeanは無視されるようです。
stacktraceを貼り付けてください – emotionlessbananas
あなたのzk-springバージョンは何ですか? –
私はzk-springを使いませんでした。私はspring.jarバージョン2.5.6をインポートしました – Ryan