2016-02-24 38 views
2

我有以下服务:如何自动装配服务作为构造函数参数?

public interface LogoutService { 
    void logoutAllUsers(); 

    void dropUserSession(SessionInformation session); 
} 

和下面的实现:

@Service 
public class LogoutServiceImpl implements LogoutService { 
    ... 

public class MyXmlBean extends ConcurrentSessionControlAuthenticationStrategy { 
    .... 

     public MyXmlBean (MySessionRegistry sessionRegistry, 
                   LogoutService logoutService) { 
      .... 

和下面的XML配置:

<bean id="MyXmlBean" class="package.MyXmlBean"> 
    <constructor-arg name="sessionRegistry" ref="mySessionRegistry" /> 
    <constructor-arg name="logoutService" ref="logoutService"/> 
    <property name="maximumSessions" value="1" /> 
</bean> 

当我开始APPLICA我看到以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myXmlBean ' defined in class path resource [context-security.xml]: Cannot resolve reference to bean 'myXmlBean ' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyXmlBean' defined in class path resource [context-security.xml]: Cannot resolve reference to bean 'logoutService' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'logoutService' is defined 

如何解决它?

+0

进口可能听起来微不足道,但是'上下文:组件scan'放置在你的配置作为本人能端看到这错误消息'没有名为'logoutService'的bean被定义 –

回答

0

正如我发现

@Service注释从错误包(非弹簧)

相关问题