`
yangzb
  • 浏览: 3503221 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

java.lang.NoClassDefFoundError: weblogic/security/

    博客分类:
  • Java
阅读更多

在 Spring 中配置了一个 WebLogic 的 Data Source,然后在 JUnit  Test 类中直接初始化加载 applicationContext.xml,当Spring Framework 初始化该 Data Source 时,出现如下的异常信息:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in URL [file:../portalWeb/WebContent/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: weblogic/security/subject/AbstractSubject
Caused by: java.lang.NoClassDefFoundError: weblogic/security/subject/AbstractSubject
    at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
    at javax.naming.InitialContext.init(InitialContext.java:223)
    at javax.naming.InitialContext.<init>(InitialContext.java:197)
    at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:106)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:84)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:122)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:147)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:90)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:101)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:164)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:151)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1057)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1024)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.divInstantiateSingletons(DefaultListableBeanFactory.java:270)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
    at org.springframework.test.AbstractSpringContextTests.loadContextLocations(AbstractSpringContextTests.java:130)
    at org.springframework.test.AbstractDependencyInjectionSpringContextTests.loadContextLocations(AbstractDependencyInjectionSpringContextTests.java:224)
    at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:110)
    at org.springframework.test.AbstractDependencyInjectionSpringContextTests.setUp(AbstractDependencyInjectionSpringContextTests.java:192)
    at junit.framework.TestCase.runBare(TestCase.java:125)
    at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    at junit.framework.TestResult$1.protect(TestResult.java:106)



经 过查找分析后得知, AbstractSubject 类存在于 WebLogic Server 的 server/lib/weblogic.jar 文件中,于是首先将其直接加入到当前 project 的 build path 中,然后再一次运行 JUnit Test,一切正常。
然后从 build path 中去掉该 jar 包,直接 run 当前的 project,发现也是一切正常。

由此可见,该 weblogc.jar 文件仅仅是在 JUnit Test 的时候才能用得到,因此没有必要放置到 project 的 lib 目录中。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics