总结原因如下: 1 目录webapp下没有web.xml文件
2 在serviceImpl层 或者 Controller层注解没写对或者没有写
3 导错包
4 比如 在Maven项目中 有一个拦截器(jar项目) 在另一个项目中要使用这个拦截器并且在(war)springmvc.xml 中也配置了拦截器,此时报错,原因是你没有把拦截器(jar项目)依赖进来,就像你说了有这个东西 没有说东西在哪
5 maven中被依赖的项目没有启动 比如A依赖B ,但是启动的时候你启动了A后启动了B ,会出现找不到依赖
<!-- 配置拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<!-- 需要拦截器的请求路径 -->
<mvc:mapping path="/**"/>
<!-- 实例化拦截器对象 -->
<bean class="com.e.ego.interceptor.UserInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
下图是:没有写@Autowired注解 和 没有web.xml
ServiceImpl层:
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.e.ego.manager.service.ManagerItemCatService;
import com.e.ego.rpc.service.TbItemCatService;
import com.e.entity.Tree;
@Service
public class MnaagerItemCatServiceImpl implements ManagerItemCatService {
//注入远程代理对象
@Autowired
private TbItemCatService tbItemCatServiceProxy;
public List<Tree> loadManagerItemCatListService(Long id) {
return tbItemCatServiceProxy.loadTbItemCatListService(id);
}
}
Controller 层:
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.e.ego.manager.service.ManagerItemCatService;
import com.e.entity.Tree;
@Controller
public class ManagerItemCatController {
@Autowired
private ManagerItemCatService managerItemCatService;
@RequestMapping("/item/cat/list")
@ResponseBody
public List<Tree> itemCatList(@RequestParam(defaultValue="0")Long id){
return managerItemCatService.loadManagerItemCatListService(id);
}
}