Spring mvc在controller中注入service时报空

小虫hh 寿光日报社 程序员  2015-10-16 05:06:36
今天配置spring mvc时一直报空,找不到问题在哪里。希望各位帮帮忙。
tomcat能正常启动,没有报错,但是在调用controller时注入的service对象为null
web.xml配置

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

applicationContext.xml已有:
<context:component-scan base-package="com"/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven />

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;

}
里面的具体逻辑就省了,很长
...全文
248 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
心随自在飞 2015-10-19
看了所有评论及回复 我也不知道了
回复
Yaphets_VJ 2015-10-19
<context:component-scan base-package="com" > <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
回复
chenjazz 2015-10-16
你就不能格式化代码在发出来啊
回复
wrong1111 2015-10-16

<context:component-scan base-package="com.ecp888.passport">
<context:include-filter type="regex"
expression=".dao..*" />
<context:include-filter type="regex"
expression=".service..*" />
</context:component-scan>

<context:annotation-config />
回复
小虫hh 2015-10-16
引用 8 楼 u011518281 的回复:
1:<context:component-scan base-package="com.*"/> 2:<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
试了,,还是不行
回复
11王风11 2015-10-16
1:<context:component-scan base-package="com.*"/> 2:<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
回复
小虫hh 2015-10-16
引用 6 楼 sinat_31240689 的回复:
spring的配置文件呢?
<context:component-scan base-package="com.dayang.*"/> <mvc:default-servlet-handler/> <mvc:annotation-driven /> 还需要别的吗?
回复
spring的配置文件呢?
回复
小虫hh 2015-10-16
引用 1 楼 shijing266 的回复:
<context:component-scan base-package="com"/> 这个包名写精确一点
版主再帮忙看一下吧
回复
小虫hh 2015-10-16
引用 3 楼 jxxiaotao 的回复:
写成com.dayang.*就行
谢了~试过,不行呢~~
回复
jxxiaotao 2015-10-16
写成com.dayang.*就行
回复
小虫hh 2015-10-16
谢谢,麻烦再详细说一下吧,这个包应该写到什么地方呢?
包结构是这样的,我改成com.dayang还是不行
回复
<context:component-scan base-package="com"/> 这个包名写精确一点
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-10-16 05:06
社区公告
暂无公告