So I'm trying to implement things mentioned in Spring's 3.1 blog post about From XML to @Configuration, but it doesn't want to work as supposed. Here is the web.xml (and that's the only xml) I'm using and the MvcFeatures and MvcBeans more or less are the same as in the blog just added few my beans.

<?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>

When trying to launch this thing up I get these messages in console:

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]

Any ideas what could be wrong? From what I understand i think it doesn't like the contextConfigLocation param values.

EDIT: Adding the MvcFeatures in case it helps..

@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));
    }
}
有帮助吗?

解决方案

Try

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

Or set the delimiters accordantly to the docs:

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

其他提示

Richards, try these.

  1. contextConfigLocation = com.example.config
  2. mark MvcFeatures class with @Configuration and @EnableWebMvc
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top