问题描述
- Spring mvc在controller注入service报空
-
今天配置spring mvc时一直报空,找不到问题在哪里。希望各位帮帮忙。
tomcat能正常启动,没有报错,但是在调用controller时注入的service对象为null
web.xml配置contextConfigLocation
/WEB-INF/classes/applicationContext.xmlrest
org.springframework.web.servlet.DispatcherServletcontextConfigLocation
classpath:applicationContext.xml1
rest
/applicationContext.xml已有:
controller代码
@Controller
@RequestMapping(value = "/sync")
public class servicecontroller extends BaseController{@javax.annotation.Resource(name = "syncClientService") private ISyncClientService syncClientService; @RequestMapping(value = "/start") @ResponseBody private String syncStart(HttpServletRequest request) throws Exception{ CreLogger.info("**********Strat invoke synchusers..."); JSONObject jsonPara = getJsonPara(request); String sychUrl = jsonPara.getString("syncurl"); SynchroniseuserResponse response = syncClientService.syncUserStart(sychUrl); if (response != null) { SynchroniseuserResponseType responseType = response.getSynchroniseuserResponse(); if (responseType.getResultCode() == 0) { CreLogger.info("**********同步成功..."); return "同步成功!"; }else { CreLogger.info("**********同步失败..."); return "同步失败!"; } }else { CreLogger.info("**********同步失败..."); return "同步失败!"; } }
}
service代码:
@Service("syncClientService")
public class syncClientService implements ISyncClientService{
private static com.dayangit.cre.util.CreLogger CreLogger = com.dayangit.cre.util.CreLogger.getLogger(servicecontroller.class);@javax.annotation.Resource(name = "AuthorizationManager") private AuthorizationManager authorizationManager; @SuppressWarnings("null") public SynchroniseuserResponse syncUserStart(String url) { try { SynchroniseUsersServiceStub stub = new SynchroniseUsersServiceStub(url); SynchroniseuserRequest request = new SynchroniseuserRequest(); SynchroniseuserRequestType requestType = new SynchroniseuserRequestType(); //设置全局同步 CreLogger.info("**********设置全局同步**********"); requestType.setSyncAll(true); ModifiedModuleInfoType moduleInfo = new ModifiedModuleInfoType(); requestType.setModifiedModuleInfo(moduleInfo); request.setSynchroniseuserRequest(requestType); SynchroniseuserResponse response = stub.synchroniseUsers(request); return response; } catch (Exception e) { CreLogger.error("exception",e); } return null; } 里面的具体逻辑就省了,很长
解决方案
检查下service的扫描路径~
解决方案二:
你mvc配置文件设置自动扫描了吗
解决方案三:
service类是不是没加注解?
时间: 2024-12-24 08:22:40