有人可以指点我在这里做错了什么,这是我得到的错误信息;
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/logicalideasJPA/contacts.html] in DispatcherServlet with name 'appServlet'
<context:property-placeholder location="classpath:hibernate.properties" />
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.logicalideasJPA.persistence" />
<context:component-scan base-package="com.logicalideasJPA.controller" />
<context:component-scan base-package="com.logicalideasJPA.dao" />
<!-- Enables the Spring MVC @Controller programming model -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- Declare a JPA entityManagerFactory -->
<beans:bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="packagesToScan" value="com.logicalideasJPA.persistence" />
<beans:property name="loadTimeWeaver">
<beans:bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</beans:property>
<beans:property name="jpaVendorAdapter">
<beans:bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<beans:property name="showSql" value="true" />
</beans:bean>
</beans:property>
</beans:bean>
<!-- Declare a transaction manager -->
<beans:bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<beans:property name="entityManagerFactory" ref="entityManagerFactory" />
<beans:property name="dataSource" ref="dataSource" />
</beans:bean>
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="${database.driver}" />
<beans:property name="url" value="${database.url}" />
<beans:property name="username" value="${database.user}" />
<beans:property name="password" value="${database.password}" />
</beans:bean>
@Controller
public class ContactController {
@Autowired
private ContactsImp serviceInter;
@RequestMapping(method = RequestMethod.GET)
public String showContactForm(Map<String, Contacts> map){
Contacts contacts = new Contacts();
map.put("contacts", contacts);
return "contacts";
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<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>
非常感谢一些帮助。 感谢
答案 0 :(得分:0)
我认为这与您从控制器返回联系人的事实有关。默认视图解析器正在查找适合的HTML文件以显示结果。 您是否尝试返回响应正文实体或指向某种视图页面?
答案 1 :(得分:0)
您似乎向“/logicalideasJPA/contacts.html”发送了请求,但没有处理此请求的控制器。
@Controller
@RequestMapping("/contacts")
public class ContactController {
@Autowired
private ContactsImp serviceInter;
@RequestMapping(method = RequestMethod.GET)
public String showContactForm(Map<String, Contacts> map){
Contacts contacts = new Contacts();
map.put("contacts", contacts);
return "contacts";
}
通过上述更改,您的请求应在/ contacts uri
处理