Reputation: 16525
I have problem to use DI in spring. I have 3 classes which one of them is abstract. I have problem to add one service no another. I got this exception:
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
I am really desperate why it cannot convert please help
my app context:
<?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>
classes:
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;
}
}
UPDATE:
ok get rid of this exception when I delete: "implements Constants" in my abstractService. Now it look like:
public abstract class AbstractService { ... }
but I have no idea which it cant implement interface where is just constants:
public interface Constants {
int BEST_OF_GAMES = 9;
}
Can someone explain me this behaviour ?
Upvotes: 0
Views: 624
Reputation: 51323
As you can see in the exception spring uses java proxies: of type [sun.proxy.$Proxy14
.
A java proxy can only be created for interfaces - not for classes.
Change your code in this way:
public interface GameService {
}
public class GameServiceImpl extends AbstractService implements GameService {
}
and your bean.xml to
<bean id="gameService" class="org.toursys.processor.service.GameServiceImpl" parent="abstractService" />
Upvotes: 1