我有一个带有web.xml配置的spring项目
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
这是我的servlet-context.xml
resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**" />
<default-servlet-handler/>
<context:component-scan base-package="pk.training.basitMahmood.web.controller" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jspx" />
</beans:bean>
这是我的控制器
@RequestMapping("/contacts")
@Controller
public class ContactController {
final Logger logger = LoggerFactory.getLogger(ContactController.class);
@Autowired
private ContactService contactService;
@RequestMapping(method = RequestMethod.GET)
public String list(Model uiModel) {
logger.info("Listing contacts");
List<Contact> contacts = contactService.findAll();
uiModel.addAttribute("contacts", contacts);
logger.info("No. of contacts: " + contacts.size());
return "contacts/list";
}
} //end of class ContactController
现在,当我选择RunonServer时,我会看到下面的页面
但是当我把网址改成 http://localhost:9090/ch17_i18nSupport/contacts
然后我得到一个错误
我的联系人文件夹中有list.jspx。为什么我没有发现错误?
谢谢
1条答案
按热度按时间cs7cruho1#
虽然basit在评论中已经解决了这个问题,但我也添加了一个答案:
没有处理程序的适配器指示
@RequestMapping
控制器中的方法未被拾取。你有电话吗<mvc:annotation-driven />
标记你的servlet-context.xml
?