-1
我構建了一個簡單的Spring Web應用程序。我有一個@RequestMapping這個簡單@Controller,但是當我運行它,我不能打的網址:我簡單的Spring web服務有什麼問題?
http://localhost:8080/labutil/all
我在做什麼錯?
package com.mycompany.ion.labutil.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.RequestMethod;
import com.nokia.ion.labutil.service.LabService;
@Controller
public class LabController {
@Autowired
private LabService labService;
@RequestMapping(value = "/all", method = RequestMethod.GET)
public String getAll() throws Exception {
List<String> list = labService.getAll();
// build fake little json formatted data
StringBuffer sb = new StringBuffer("{");
for (String s : list) {
sb.append("{ "+s+" }, ");
}
sb.append("}");
return sb.toString();
}
}
你還可以嘗試http:// localhost:8080/all嗎?它似乎像一個URL問題給我。 – Kael53
您可否請您發佈您的application-context.xml文件。 – SachinSarawgi
您沒有在控制器的任何位置設置'/ labutil'。 @ Kael53建議應該可行(可能在URL中添加應用上下文) – Alfabravo