gpt4 book ai didi

java - 无法将 DWR 与 Spring 合并

转载 作者:太空宇宙 更新时间:2023-11-04 11:59:23 25 4
gpt4 key购买 nike

使用 spring 4.2.0、Dwr 3。使用注解创建所有 Spring Controller 、服务和 daos。工作正常,直到仅在 Spring 环境中。尝试将 DWR 添加为单独的 spring Controller 服务对象不会注入(inject)该 DWR Controller 。使用 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 是

@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 Controller 并删除 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不会启动,启动时出现异常/错误

最佳答案

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

关于java - 无法将 DWR 与 Spring 合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41068051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com