无法将DWR与Spring合并

时间:2016-12-09 20:06:25

标签: java spring spring-mvc dwr

使用spring 4.2.0,Dwr 3。 使用注释创建所有弹簧控制器,服务和daos。工作正常,直到它只在春天的环境。尝试将DWR添加为单独的弹簧控制器服务对象不会注入该DWR控制器。使用NullPointerException获取以下错误

found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

以下是代码段。 Dwr控制器是

@Controller
@RemoteProxy(name = "dwrDemo")
public class DwrDemoController {
@Autowired
private BrandNameService brandNameService;


public void setBrandNameService(BrandNameService brandNameService) {
    this.brandNameService = brandNameService;
}


@RemoteMethod
public List<String> getEmployeeDetails(int id) {
   return brandNameService.getEmployeeDetails(id);
}
:
}

服务类就像

@Service("brandNameService")
@Transactional
public class BrandNameServiceImpl implements BrandNameService{
  public List<String> getEmployeeDetails(int id) {
     return brandNameDAO.getEmployeeDetails(id);
  }
:
}

如果我在xml中定义DWR控制器并删除DWR Controller中的所有注释,则服务器在没有初始化服务对象的情况下启动(这里调用dwr获取NullPointerException) 下面是XML

<beans:bean id="dwrDemoController"
    class="com.classified.dwr.controller.DwrDemoController">
    <!-- <beans:property name="brandNameService" ref="brandNameService"/> -->
    <dwr:remote javascript="dwrService">
        <dwr:include method="getEmployeeDetails" />
    </dwr:remote>
</beans:bean>

如果我取消注释brandNameService,那么tomcat没有起来,在上升时遇到异常/错误

1 个答案:

答案 0 :(得分:0)

当我在applicationContext.xml中定义所有bean而不是myapp-servlet.xml时,它起了作用。