Controller中:
*/
@RestController
@Api(value = "/manage",description = "站点管理")
@Path("/manage")
public class ManageEndpoint {
@Autowired
private DeviceService deviceService;
@GET
@Path("/site/{siteId:[0-9]+}")
@ApiOperation(value = "获取站点信息",notes = "根据id获取站点",response = Response.class)
@ApiResponses(value ={
@ApiResponse(code = 200,message = "操作成功"),
@ApiResponse(code = 404,message = "未找到相关id")
})
public Response SiteById(@ApiParam(name = "siteId",value = "站点Id",required = true) @PathParam("siteId") Integer siteId){
if (deviceService == null){
System.out.println("-----> deviceService is null");
}
Device device = deviceService.selectByPrimaryKey(siteId);
if (null != device)
{
return Response.status(200).entity(device).build();
}
else
{
return Response.status(404).entity(0).build();
}
}
deviceService 为null。
解决方法:在web.xml中添加
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext.xml</param-value> </context-param>