简体   繁体   English

引起原因:javax.naming.NameNotFoundException; 剩余名称“ env / jdbc / PSC”

[英]Caused by: javax.naming.NameNotFoundException; remaining name 'env/jdbc/PSC'

I have some trouble above. 我上面有些麻烦。 I don't know which problem actually is. 我不知道实际上是哪个问题。 I tried to solve this problem but I can't find any material on the Internet at all. 我试图解决此问题,但是我根本无法在Internet上找到任何资料。 If you have some clue, please, leave comment or answer. 如果您有任何线索,请发表评论或回答。

Test below: 测试如下:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = {JpaConfig.class, ServicesConfig.class, restService.com.websystique.springmvc.configuration.RestConfig.class})
public class BranchControllerTest {

    @Autowired
    private WebApplicationContext wac;


    private MockMvc mockMvc;

    @Before
    public void setup() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();    }

    @Test
    public void getFoo() throws Exception {
//        MvcResult result=this.mockMvc.perform(get("/branch?id=2")).andExpect(status().isOk()).andReturn();
//        String restCall = result.getResponse().getContentAsString();
//        JSONParser parser = new JSONParser();
//        System.out.println(restCall);
//        Object obj = parser.parse(restCall);
//        JSONObject jsonObj = (JSONObject) obj;
//        JSONArray jo =(JSONArray)  jsonObj.get("listOfItems");
//        System.out.println(jsonObj.get("listOfItems"));
//        System.out.println(((JSONObject)jo.get(0)).get("naviDate"));
//        assertEquals(jsonObj.get("size"),1L);
//        assertEquals(((JSONObject)jo.get(0)).get("primaryKey"),2L);
    }
}

this is my web.xml (nothing special) 这是我的web.xml(没什么特别的)

<?xml -->
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
    <display-name>ProductCatalog</display-name>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <context-param>
        <description>Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>${vaadin.productionMode}</param-value>
    </context-param>
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            com.psc.config.JpaConfig, com.psc.config.ServicesConfig, restService.com.websystique.springmvc.configuration.RestConfig
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

... rows
</web-app>

and this row i have in persistence.xml 这行我在persistence.xml中

...
 <non-jta-data-source>java:comp/env/jdbc/PSC</non-jta-data-source>
...

my stacktrace: 我的堆栈跟踪:

java.lang.IllegalStateException: Failed to load ApplicationContext

    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:183)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:123)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.psc.config.JpaConfig: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/PSC'; nested exception is javax.naming.NameNotFoundException; remaining name 'env/jdbc/PSC'
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:133)
    at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:60)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
    ... 29 more
Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/PSC'; nested exception is javax.naming.NameNotFoundException; remaining name 'env/jdbc/PSC'
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:48)
    at org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.parsePersistenceUnitInfo(PersistenceUnitReader.java:260)
    at org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.parseDocument(PersistenceUnitReader.java:182)
    at org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:134)
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.readPersistenceUnitInfos(DefaultPersistenceUnitManager.java:487)
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:440)
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:424)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:310)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 44 more
Caused by: javax.naming.NameNotFoundException; remaining name 'env/jdbc/PSC'
    at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:538)
    at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:569)
    at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:584)
    at org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:108)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:45)
    ... 54 more

Your webapplication includes a database which your testcase is trying to use. 您的Web应用程序包括您的测试用例试图使用的数据库。 To connect to that database, it tries to resolve said JNDI reference, which isn't available in your testcase. 要连接到该数据库,它将尝试解析所述JNDI参考,该参考在您的测试用例中不可用。

Solution: Modify your configuration to either have a test database, or modify your test to not use databases (probably better). 解决方案:将配置修改为具有测试数据库,或者将测试修改为不使用数据库(可能更好)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jetty mysql连接池配置错误:javax.naming.NameNotFoundException; 剩余名称&#39;env / jdbc / ---(mysql 5.0 + jetty 7.0.1) - Jetty mysql connection-pool configuration error: javax.naming.NameNotFoundException; remaining name 'env/jdbc/---(mysql 5.0+jetty 7.0.1) Weblogic 异常:javax.naming.NameNotFoundException:无法解析“jdbc.payment”。 解决了&#39;jdbc&#39;; 剩余名称“付款” - Weblogic exception : javax.naming.NameNotFoundException: Unable to resolve 'jdbc.payment'. Resolved 'jdbc'; remaining name 'payment' Spring Boot构建正常,但抛出javax.naming.NameNotFoundException:剩余名称:运行时的env / jmx / runtime - Spring Boot builds fine but throws javax.naming.NameNotFoundException: remaining name: env/jmx/runtime when running jdbc javax.naming.NameNotFoundException - jdbc javax.naming.NameNotFoundException 根异常是 javax.naming.NameNotFoundException: Name jdbc not found in context &quot;java:comp/env&quot; - Root exception is javax.naming.NameNotFoundException: Name jdbc not found in context "java:comp/env" javax.naming.NameNotFoundException - javax.naming.NameNotFoundException javax.naming.NameNotFoundException:名称[jdbc / skynetdb]未绑定在此Context中。 找不到[jdbc] - javax.naming.NameNotFoundException: Name [jdbc/skynetdb] is not bound in this Context. Unable to find [jdbc] javax.naming.NameNotFoundException:名称[jdbc / spitterDS]未绑定在此Context中。找不到[jdbc] - javax.naming.NameNotFoundException: Name [jdbc/spitterDS] is not bound in this Context. Unable to find [jdbc] javax.naming.NameNotFoundException:名称[jdbc / rhwebDB]未绑定在此Context中。找不到[jdbc] - javax.naming.NameNotFoundException: Name [jdbc/rhwebDB] is not bound in this Context. Unable to find [jdbc] javax.naming.NameNotFoundException:名称[comp / env]在此上下文中未绑定。 在Tomcat中找不到[comp] - javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context. Unable to find [comp] in Tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM