开发者

Tiles Config bean throws exception: TestNG+Spring 3+Tiles2

开发者 https://www.devze.com 2023-03-29 19:10 出处:网络
I\'m trying to run a TestNG+Spring+JPA+Hibernate \'Hello World\' test. The execution results in a NullPointerException, the tiles configurer bean fails.

I'm trying to run a TestNG+Spring+JPA+Hibernate 'Hello World' test. The execution results in a NullPointerException, the tiles configurer bean fails.

The exception:

2011-08-20 18:12:18,547 [main] INFO  org.springframework.web.servlet.view.tiles2.TilesConfigurer  - TilesConfigurer: adding definitions [/WEB-INF/tiles/tiles.xml]
        2011-08-20 18:12:18,552 [main] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory  - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@68cb6b: defining beans [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#0,org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor#0,org.springframework.security.methodSecurityMetadataSourceAdvisor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,nethawalaDS,jspViewResolver,tilesViewResolver,tilesConfigurer,nethawalaEMF,transactionManager,jpaVendorAdapter,validator,auditLog,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,logoutHandlerBean,userDetailsService,customAuthenticationFailureHandlerBean,customAuthenticationSuccessHandlerBean,httpSessionEventListener,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.spr开发者_JS百科ingframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.scheduling.annotation.internalAsyncAnnotationProcessor,org.springframework.scheduling.annotation.internalScheduledAnnotationProcessor,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,homeController,userSessionController,NHUserDAOImpl,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,nethawalaProperties,placeholderConfig]; root of factory hierarchy
        2011-08-20 18:12:18,563 [main] ERROR org.springframework.test.context.TestContextManager  - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@fdfc58] to prepare test instance [com.tigermindz.test.FacultyDaoTest@1afae45]
        java.lang.IllegalStateException: Failed to load ApplicationContext
            at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
            at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
            at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
            at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
            at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:133)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:76)
            at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:525)
            at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:202)
            at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:130)
            at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:173)
            at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
            at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
            at org.testng.TestRunner.privateRun(TestRunner.java:749)
            at org.testng.TestRunner.run(TestRunner.java:600)
            at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
            at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
            at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
            at org.testng.SuiteRunner.run(SuiteRunner.java:223)
            at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
            at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
            at org.testng.TestNG.runSuitesSequentially(TestNG.java:1039)
            at org.testng.TestNG.runSuitesLocally(TestNG.java:964)
            at org.testng.TestNG.run(TestNG.java:900)
            at org.testng.TestNG.privateMain(TestNG.java:1182)
            at org.testng.TestNG.main(TestNG.java:1146)
        Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tilesConfigurer' defined in class path resource [nethawala-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
            at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
            at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
            at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
            at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
            ... 28 more
        Caused by: java.lang.NullPointerException
            at org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory$SpringWildcardServletTilesApplicationContext.(SpringTilesApplicationContextFactory.java:72)
            at org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory.createApplicationContext(SpringTilesApplicationContextFactory.java:55)
            at org.springframework.web.servlet.view.tiles2.TilesConfigurer.afterPropertiesSet(TilesConfigurer.java:335)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
            ... 41 more

My applicationContext.xml, only showing the tiles config bean def:

<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
    <list>
        <value>/WEB-INF/tiles/tiles.xml</value>
    </list>
</property>
</bean>

Did a lot of googling, only thing found, people mentioned about cglib and/or asm jars in conflict with spring and hibernate dependencies. I don't think that is applicable here however my lib folder has the following jars, sorry not in order:

    ./tiles-template-2.2.2.jar
    ./spring-security-acl-3.0.5.RELEASE.jar
    ./org.springframework.context-3.0.5.RELEASE.jar
    ./hibernate-jpa-2.0-api-1.0.0.Final.jar
    ./tiles-api-2.2.2.jar
    ./validation-api-1.0.0.GA.jar
    ./org.springframework.web.servlet-3.0.5.RELEASE.jar
    ./hsqldb.jar
    ./spring-security-taglibs-3.0.5.RELEASE.jar
    ./commons-pool-1.5.6.jar
    ./aspectjrt-1.6.8.jar
    ./commons-beanutils-1.8.3.jar
    ./org.springframework.aop-3.0.5.RELEASE.jar
    ./spring-security-core-3.0.5.RELEASE.jar
    ./commons-collections-3.1.jar
    ./org.springframework.web-3.0.5.RELEASE.jar
    ./jstl-1.2.jar
    ./org.springframework.expression-3.0.5.RELEASE.jar
    ./dom4j-1.6.1.jar
    ./org.springframework.orm-3.0.5.RELEASE.jar
    ./log4j-1.2.16.jar
    ./org.springframework.beans-3.0.5.RELEASE.jar
    ./tiles-servlet-2.2.2.jar
    ./poi-3.7-20101029.jar
    ./spring-security-aspects-3.0.5.RELEASE.jar
    ./slf4j-api-1.6.1.jar
    ./aopalliance-1.0.jar
    ./slf4j-simple-1.6.1.jar
    ./hibernate3.jar
    ./slf4j-ext-1.6.1.jar
    ./spring-security-web-3.0.5.RELEASE.jar
    ./jta-1.1.jar
    ./asm-3.3.1.jar
    ./org.springframework.test-3.0.5.RELEASE.jar
    ./spring-security-config-3.0.5.RELEASE.jar
    ./org.springframework.core-3.0.5.RELEASE.jar
    ./org.springframework.asm-3.0.5.RELEASE.jar
    ./tiles-jsp-2.2.2.jar
    ./testng-6.0.1.jar
    ./commons-digester-2.1.jar
    ./commons-logging-1.1.1.jar
    ./org.springframework.transaction-3.0.5.RELEASE.jar
    ./javax.inject.jar
    ./commons-dbcp-1.4.jar
    ./slf4j-log4j12-1.6.1.jar
    ./hibernate-validator-4.1.0.Final.jar
    ./javassist-3.12.0.GA.jar
    ./tiles-core-2.2.2.jar
    ./aspectjweaver-1.6.8.jar
    ./org.springframework.jdbc-3.0.5.RELEASE.jar
    ./jackson-all-1.7.5.jar
    ./jstl-api-1.2.jar
    ./antlr-2.7.6.jar
    ./cglib-2.2.jar

The test class is as follows:

@ContextConfiguration(locations = { "classpath:test-servlet.xml" })
public class FacultyDaoTest extends AbstractTransactionalTestNGSpringContextTests {

    private final XLogger logger = XLoggerFactory.getXLogger(FacultyDaoTest.class);

    @Inject
    FacultyDAO facultyDao;

    @BeforeClass
    public void setUp() {
        logger.entry();    
        System.out.println("Inside setup");    
    }

    @Test(groups = { "fast" })
    @Rollback(value = false)
        public void createFaculty() {
        Faculty f = new Faculty();
        f.setFirstName("John");
        f.setLastName("Frost");
        f.setCpsoNumber("23198");

        f = facultyDao.makePersistent(f);

        assert(f.getId() > 0);    
    }

    @Test(groups = { "fast" })
    public void aFastTest() {
        logger.entry();    
        logger.info("Inside a Fast test");
    }

    @Test(groups = { "slow" })
    public void aSlowTest() {
        logger.entry();    
        logger.info("Inside a Slow test");
    }
}

Any pointers will be greatly appreciated.


Your test load a web app specific configuration file, but your test environment does not provide the required files:

You need to separate the Web Application specific configuration from the one the works wihtout web application context.

Then use for the test the one that works without Web Application.

For you that mean: remove the Tiles Configuration for the test configuration. Because in the test the /WEB-INF/tiles/tiles.xml file is not available.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号