0

Совсем недавно я начал изучать Java, в конце курса мне дали задание написать небольшой (в сравнении с проектами компании) учебный проект. Когда мне рассказывали про spring, а именно про context.xml, на вопрос, а что здесь и как:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-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.xsd">

мне отвечали: так будет везде, пока забей! Так вот, теперь, мне надо добавить в свой проект AJAX, я взял пример отсюда, запусти его, он заработал. Пытаюсь то же самое сделать в моем проекте, не работает( Разница между проектами, только в этих xml.

Мой mvc-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-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.xsd">

<context:component-scan base-package="com.luxoft.buying_currency.controllerUI" />
<!--<mvc:annotation-driven />-->
<!--<mvc:resources mapping="/**" location="/" />-->

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/pages/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

servlet-context.xml из примера

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 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.blogspot.alexeydl" />
</beans:beans>

Естественно пути все меняю во второй xml на свои, вставляю к себе в проект, мой проект перестает работать, оставляю свою xml не работает AJAX. Мой проект

Как решить эту проблему? Времени читать про contxt.xml особо нету, по первым ссылкам в гугле не нашел.

4
  • а если расскомментировать <mvc:annotation-driven /> то будет работать? 7 янв 2017 в 19:08
  • тогда моя прога перестает работать
    – sanchopa
    7 янв 2017 в 19:17
  • какие-нибудь ошибки? а без этой строки все работает? 7 янв 2017 в 19:25
  • Если расскоментировать эту строчку... то отваливается сессия. Программа сначала работает, но когда я пытаюсь обратиться к объекту, который получаю из сессии, программа не работает. nullpointerexception
    – sanchopa
    7 янв 2017 в 19:47

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.