簡體   English   中英

如何自動連接服務作為構造函數參數?

[英]How to autowire service as constructor argument?

我有以下服務:

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>

當我啟動應用程序時-我看到以下錯誤:

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

如何解決?

我發現

@Service注釋是從錯誤的包中導入的(非春季)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM