我的控制器继续返回错误 "The requested resource is not available"

My controller keep on returning the error "The requested resource is not available"

我有这个控制器。

@Controller
@RequestMapping("/addr")
public class AddressController
{

   public List<Address> addresses = (List<Address>) Collections.synchronizedCollection(new LinkedList<Address>());

   @RequestMapping("/new")
   public String getAddressForm()
   {
     return "addressProject/addressBook";
   }

   @RequestMapping("/submit")
   public ModelAndView submitForm(String name, String email, String group, String phoneNumber, String address){
      Address addr = new Address(name, email, group, phoneNumber, address);
      addresses.add(addr);

      ModelAndView modelandview = new          ModelAndView("/addressproject/newAddress");

      return modelandview;      
   }
}

并且出于某种原因,本地主机仅显示请求的资源不可用。

我使用的是正确的 url,即 http://localhost:8080/ExampleSpringWebApp/smvc/addr/new

你确定 http://localhost:8080/ExampleSpringWebApp/smvc/addr/new is the correct URL? I don't see smvc anywhere in your @RequestMapping annotation. What about http://localhost:8080/ExampleSpringWebApp/addr/new 吗?

你的@Controller class 被spring 实例化了吗?您的 spring 上下文中有 <context:component-scan /><mvc:annotation-driven /> 吗?

你有意见吗"addressProject/addressBook"? ViewResolver 能找到吗?确切的错误消息是什么?

ClassCastException

nested exception is java.lang.ClassCastException: java.util.Collections$SynchronizedCollection cannot be cast to java.util.List

您调用 Collections.synchronizedCollection 但将其转换为 List 的结果。 Collections.synchronizedCollection() returns 一个集合 - 没有列表。请改成

 public Collection<Address> addresses = (Collection<Address>) Collections.synchronizedCollection(new LinkedList<Address>());