Printemps basé sur Java config et JUnit ne fonctionne pas lorsque webmvc est activé

J'ai commencé avec un nouveau Printemps 3.2.0.COMMUNIQUÉ de en fonction de l'application et je voulais vraiment en finir avec XML de configuration depuis sa un nouveau projet, mais j'ai couru dans un mur quand il s'agit de l'écriture Junit tests.

Ici est La java config (WebConfig.java):
package com.myapp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan("com.myapp.controllers")
public class WebConfig{
     @Bean
     public InternalResourceViewResolver configureInternalResourceViewResolver() {
         InternalResourceViewResolver resolver = new InternalResourceViewResolver();
         resolver.setPrefix("/WEB-INF/views/");
         resolver.setSuffix(".jsp");
         return resolver;
     }
}

C'est le de la classe de test:

package com.myapp.test.integration;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import com.myapp.config.WebConfig;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={ WebConfig.class})
@WebAppConfiguration
public class HomeControllerTest {

    @Test
    public void testController(){
        System.out.println("Executing test");
    }   

}

Quand j'essaie de exécuter le test j'obtiens le suivant(je l'ai activé debug pour obtenir plus d'infos):

DEBUG: org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.myapp.test.integration.HomeControllerTest].
DEBUG: org.springframework.test.context.support.AbstractDelegatingSmartContextLoader - Delegating to AnnotationConfigWebContextLoader to process context configuration [ContextConfigurationAttributes@252d252d declaringClass = 'com.myapp.test.integration.HomeControllerTest', locations = '{}', classes = '{class com.myapp.config.WebConfig}', inheritLocations = true, initializers = '{}', inheritInitializers = true, contextLoaderClass = 'org.springframework.test.context.ContextLoader'].
DEBUG: org.springframework.test.context.ContextLoaderUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.context.TestContextManager - @TestExecutionListeners is not present for class [class com.myapp.test.integration.HomeControllerTest]: using defaults.
DEBUG: org.springframework.test.context.TestContextManager - Could not instantiate default TestExecutionListener class [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes available.
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.myapp.test.integration.HomeControllerTest]
DEBUG: org.springframework.test.context.support.AbstractDelegatingSmartContextLoader - Delegating to AnnotationConfigWebContextLoader to load context from [WebMergedContextConfiguration@a580a58 testClass = HomeControllerTest, locations = '{}', classes = '{class com.myapp.config.WebConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader'].
DEBUG: org.springframework.test.context.web.AbstractGenericWebContextLoader - Loading WebApplicationContext for merged context configuration [WebMergedContextConfiguration@a580a58 testClass = HomeControllerTest, locations = '{}', classes = '{class com.myapp.config.WebConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader'].
DEBUG: org.springframework.test.context.web.AnnotationConfigWebContextLoader - Registering annotated classes: {class com.myapp.config.WebConfig}
INFO : org.springframework.web.context.support.GenericWebApplicationContext - Refreshing org.springframework.web.context.support.GenericWebApplicationContext@5cf15cf1: startup date [Wed Jan 30 17:42:16 EST 2013]; root of context hierarchy
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
DEBUG: org.springframework.ui.context.support.UiApplicationContextUtils - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@7a487a48]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@61266126: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,webConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,homeController,org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration,requestMappingHandlerMapping,mvcContentNegotiationManager,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,defaultServletHandlerMapping,requestMappingHandlerAdapter,mvcConversionService,mvcValidator,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,configureInternalResourceViewResolver]; root of factory hierarchy
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.myapp.controllers.HomeController.home(java.util.Locale,org.springframework.ui.Model)
DEBUG: org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/spring.liveBeansView.mbeanDomain]
Jan 30, 2013 5:42:17 PM null null
SEVERE: javaAccessorNotSet
DEBUG: org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/spring.liveBeansView.mbeanDomain] not found - trying original name [spring.liveBeansView.mbeanDomain]. javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
DEBUG: org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [spring.liveBeansView.mbeanDomain]
DEBUG: org.springframework.test.context.support.DirtiesContextTestExecutionListener - After test class: context [[TestContext@12a312a3 testClass = HomeControllerTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@a580a58 testClass = HomeControllerTest, locations = '{}', classes = '{class com.myapp.config.WebConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader']]], dirtiesContext [false].
  • Êtes-vous à l'aide de printemps 3.2 pour toute raison spécifique? Je pense que ça devrait être mieux, si vous commencez à partir de zéro, pour utiliser le printemps de démarrage: projets.printemps.io/spring-boot de printemps (4)
InformationsquelleAutor MickJ | 2013-01-30