Spring 3.1 нет xml, просто не работает конфигурация - PullRequest
1 голос
/ 21 марта 2011

Итак, я пытаюсь реализовать вещи, упомянутые в блоге Spring 3.1 о От XML до @ Configuration , но он не хочет работать так, как предполагалось.Вот web.xml (и это единственный xml), который я использую, и MvcFeatures и MvcBeans более или менее такие же, как в блоге, добавили несколько моих бинов.

<?xml version="1.0" encoding="UTF-8"?>
<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_1.xsd"
         version="3.1">

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>

        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                com.example.config.MvcFeatures 
                com.example.config.MvcBeans
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file></welcome-file>
    </welcome-file-list>

</web-app>

При попыткезапустить эту штуку, я получаю следующие сообщения в консоли:

21 Mar 2011 00:52:58,203 INFO  org.springframework.web.context.support.AnnotationConfigWebApplicationContext []: No annotated classes found for specified class/package [com.example.config.MvcFeatures]
21 Mar 2011 00:52:58,203 INFO  org.springframework.web.context.support.AnnotationConfigWebApplicationContext []: No annotated classes found for specified class/package [com.example.config.MvcBeans]

Есть идеи, что может быть не так?Из того, что я понимаю, я думаю, что ему не нравятся значения параметров contextConfigLocation.

РЕДАКТИРОВАТЬ: Добавление MvcFeatures в случае, если это помогает ..

@FeatureConfiguration
public class MvcFeatures {

    /**
     * Enables the Spring MVC @Controller programming model.
     */
    @Feature
    public MvcAnnotationDriven annotationDriven(ConversionService conversionService) {
        return new MvcAnnotationDriven().conversionService(conversionService)
                .argumentResolvers(new CustomArgumentResolver());
    }

    /**
     * Maps '/' requests to the 'home' view.
     */
    @Feature
    public MvcViewControllers viewController() {
        return new MvcViewControllers("/", "index");
    }

    /**
     * Enables Spring's component scanning feature.
     */
    @Feature
    public ComponentScanSpec componentScan() {
        return new ComponentScanSpec("com.example.controllers").excludeFilters(
                new AnnotationTypeFilter(Configuration.class), new AnnotationTypeFilter(
                        FeatureConfiguration.class));
    }
}

Ответы [ 2 ]

2 голосов
/ 21 марта 2011

Попробуйте

    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            com.example.config.**
        </param-value>
    </init-param>

Или установите разделители в соответствии с документами:

Configuration locations must consist of one or more comma- or space-delimited 
fully-qualified @Configuration classes. Fully-qualified packages may also 
be specified for component-scanning
0 голосов
/ 09 июля 2014

Ричардс, попробуйте это.

  1. contextConfigLocation = com.example.config
  2. пометьте класс MvcFeatures @Configuration и @ EnableWebMvc
...