2017-09-09 1 views
0

Feder mvc Hello World writning Code aber immer Fehler von Angeforderte resourses nicht avilable ist .i ist Entsendung hier webxml, Servletkontext und Anwendungskontext Code und Controller ` web.xmlhallo Test für das Frühjahr mvc angefordert resoursces bekommen ist nicht verfügbar

<web-app 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_3_0.xsd" 
 
     version="3.0"> 
 
    <display-name>Archetype Created Web Application</display-name> 
 
    
 
    <context-param> 
 
    <param-name>ApplicationContext</param-name> 
 
    <param-value>/WEB-INF/applicationContext.xml</param-value> 
 
    </context-param> 
 
    
 
    
 
    <servlet> 
 
    <servlet-name>SpringMVC</servlet-name> 
 
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
 
    <load-on-startup>1</load-on-startup> 
 
    </servlet> 
 
    
 
    
 
    <servlet-mapping> 
 
    <servlet-name>SpringMVC</servlet-name> 
 
    <url-pattern>/</url-pattern> 
 
    </servlet-mapping> 
 
    
 
<listener> 
 
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
 
</listener> 
 
<listener> 
 
<listener-class>org.springframework.web.context.request.requestcontextlistener</listener-class> 
 
</listener> 
 
</web-app>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> 
 

 
<beans xmlns="http://www.springframework.org/schema/beans" 
 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
     xmlns:tx="http://www.springframework.org/schema/tx" 
 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
 
     xmlns:context="http://www.springframework.org/schema/context" 
 
     xsi:schemaLocation=" 
 
http://www.springframework.org/schema/beans 
 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
 
http://www.springframework.org/schema/tx 
 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
 
http://www.springframework.org/schema/context 
 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
 
http://www.springframework.org/schema/mvc 
 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
 
    
 
<context:annotation-config /> 
 
<context:component-scan base-package="com" /> 
 
<mvc:annotation-driven /> 
 
<mvc:resources location="/resources/" mapping="/resources/**" /> 
 
    
 
<bean id="dataSource" class="org.apache.commons.dbcp BasicDataSource"> 
 
<!-- <property name="DriverClassName" class="com.mysql.jdbc.Driver" /> --> 
 
<property name="driverClassName" value="com.mysql.jdbc.Driver"/> 
 
<property name="url" value="jdbc:mysql://localhost/spring_test"/> 
 
<property name="username" value="root" /> 
 
<property name="password" value="" /> 
 
    
 
</bean> 
 
    
 
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" > 
 
<property name="dataSource" ref="dataSource" /> 
 
<property name="packagesToScan" value="com.entities"></property> 
 
<property name="hibernateProperties"> 
 
<!-- <props key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</props> --> 
 
    \t \t \t <props> 
 
       <prop key="hibernate.show_sql">false</prop> 
 
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
 
       <prop key="hibernate.cache.use_query_cache">false</prop> 
 
       <prop key="hibernate.default_schema">spring-test</prop> 
 
       <prop key="format_sql">true</prop> 
 
       <prop key="use_sql_comments">true</prop> 
 
       <prop key="hibernate.enable_lazy_load_no_trans">true</prop> 
 
      </props> 
 
</property> 
 
    
 
</bean> 
 
<tx:annotation-driven transaction-manager="transactionManager"/> 
 
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
 
<property name="sessionFactory" ref="sessionFactory" /> 
 
    
 
</bean> 
 
    
 
</beans>

springMvcServlet.xml

<?xml version="1.0" encoding="UTF-8"?> 
 
<beans xmlns="http://www.springframework.org/schema/beans" 
 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
     xmlns:tx="http://www.springframework.org/schema/tx" 
 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
 
     xmlns:context="http://www.springframework.org/schema/context" 
 
     xsi:schemaLocation=" 
 
http://www.springframework.org/schema/beans 
 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
 
http://www.springframework.org/schema/tx 
 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
 
http://www.springframework.org/schema/context 
 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
 
http://www.springframework.org/schema/mvc 
 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
 
    
 
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
 
<property name="viewResolver" value="org.springframework.web.servlet.view.UrlBasedViewResolve" /> 
 
    <property name="prefix" value="/WEB-INF/views/" /> 
 
    <property name="suffix" value=".jsp"/> 
 
</bean> 
 
    
 
    
 
    
 
</beans>
hier ist Controller-

package com.controllers; 
 

 
import org.springframework.stereotype.Controller; 
 
import org.springframework.web.bind.annotation.RequestMapping; 
 
import org.springframework.web.bind.annotation.RequestMethod; 
 
import org.springframework.web.servlet.ModelAndView; 
 
@Controller 
 
/*@RequestMapping(value="/users")*/ 
 
public class UserController { 
 
\t 
 
\t @RequestMapping(value="/hello", method=RequestMethod.GET) 
 
\t public ModelAndView getPage(){ 
 
\t \t ModelAndView view= new ModelAndView("hello"); 
 
\t \t return view; 
 
\t } 
 

 
}

hallo mein jsp Seite hello.j ist sp in Aussicht Ordner enter image description here

nach Rumming in Server bekam ich den Fehler "Typ Statusbericht

Nachricht/TestSpring/

Beschreibung Die angeforderte Ressource ist nicht verfügbar."

+0

Auf welche URL versuchen Sie zuzugreifen? Verfügen Sie über einen Controller, der dieser URL zugeordnet ist? –

+0

Können Sie die genaue Fehlermeldung ausgeben (als Bild wenn möglich) –

+0

java.lang.ClassNotFoundException: org.springframework.web.context.request.requestcontextlistener – Allahrakha

Antwort

0

In Ihrem web.xml param name für context-param ist nicht korrekt. Es sollte contextConfiguration sein. Ändern Sie es in diese

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/applicationContext.xml</param-value> 
</context-param> 
Verwandte Themen