@Bean注释方法发生NoSuchBeanDefinitionException

时间:2018-03-08 11:28:36

标签: java spring-mvc dependency-injection

我有一个类 ServerSentEventsConfig.java ,它有一个用@Bean&注释的方法。返回org.springframework.web.servlet.mvc.method.annotation.SseEmitter实例。我试图在Controller类中自动装配这个bean但由于

我在类上得到 UnsatisfiedDependencyException
package com.forum.config;

@Configuration
public class ServerSentEventsConfig {

@Bean(name="userEventsEmmitter")
public ResponseBodyEmitter getEmmitter(){
    return new SseEmitter();
  }
}

ServerSentEventsConfig.java

package com.forum.controllers;

@Controller
public class UserActivityController {

@Autowired
private UserActivityService userActivityService;

@Autowired
private SseEmitter userEventsEmmitter;


@RequestMapping("/userActivity")
public ResponseBodyEmitter  activityFeed() {
    return userEventsEmmitter;
}

}

UserActivityController.java

<context:component-scan base-package="com.forum.*"
    annotation-config="true" />

组件扫描已在applicationContext.xml

中启用
@Order(1)
public class ApplicationInit extends
    AbstractAnnotationConfigDispatcherServletInitializer {


@Override
protected WebApplicationContext createRootApplicationContext() {
    // TODO Auto-generated method stub
    return new XmlWebApplicationContext();
}

@Override
protected Class<?>[] getRootConfigClasses() {
    // TODO Auto-generated method stub
     return new Class[] { UCFSecurityConfig.class };
}

@Override
protected Class<?>[] getServletConfigClasses() {
    // TODO Auto-generated method stub
    return null;
}

@Override
protected String[] getServletMappings() {
    // TODO Auto-generated method stub
    return null;
}

}

不确定为什么SseEmitter实例没有注册为bean。我在这里错过了什么?另外,我正在扩展 AbstractAnnotationConfigDispatcherServletInitializer 。是否因为这种情况发生了一些冲突?

$("#removeTask").click(
  function(){
    $("#taskchecklist li").find(":checked").remove();
  }
);

0 个答案:

没有答案