我在春天使用 DI 时遇到问题。我有 3 个类,其中一个是抽象的。我在添加一项服务时遇到问题。我得到了这个例外:
Caused by: java.lang.IllegalStateException: Cannot convert value of type [sun.proxy.$Proxy14 implementing org.toursys.processor.service.Constants,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.toursys.processor.service.GameService] for property 'gameService': no matching editors or conversion strategy found
我真的很绝望为什么它不能转换请帮忙
我的应用上下文:
<?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" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<import resource="repositoryContext.xml" />
<bean id="abstractService" class="org.toursys.processor.service.AbstractService" abstract="true">
<property name="tournamentAggregationDao" ref="tournamentAggregationDao" />
</bean>
<bean id="gameService" class="org.toursys.processor.service.GameService" parent="abstractService" />
<bean id="groupService" class="org.toursys.processor.service.GroupService" parent="abstractService">
<property name="gameService" ref="gameService" />
</bean>
</beans>
类:
public abstract class AbstractService implements Constants {
protected TournamentAggregationDao tournamentAggregationDao;
protected final Logger logger = LoggerFactory.getLogger(getClass());
@Required
public void setTournamentAggregationDao(TournamentAggregationDao tournamentAggregationDao) {
this.tournamentAggregationDao = tournamentAggregationDao;
}
}
--
public class GameService extends AbstractService {
}
--
public class GroupService extends AbstractService {
private GameService gameService;
@Required
public void setGameService(GameService gameService) {
this.gameService = gameService;
}
}
更新:
好的,当我在我的 abstractService 中删除:“implements Constants”时摆脱这个异常。现在它看起来像:
public abstract class AbstractService { ... }
但我不知道它不能实现接口,其中只是常量:
public interface Constants {
int BEST_OF_GAMES = 9;
}
有人可以向我解释这种行为吗?