Spring Boot Using Embedded Tomcat with JNDI

后端 未结 2 1683
无人及你
无人及你 2020-12-19 21:49

I am using Spring Boot with Embedded Tomcat and attempting to use JNDI but getting the following error:

javax.naming.NameNotFoundException: Name [jdbc/dataSource]

2条回答
  •  忘掉有多难
    2020-12-19 22:14

    You need to set lookupOnStartup to false on the JndiObjectFactoryBean.

    Alternatively, if you need the lookup to work during startup, then this answer may be of interest.

    Edit: you've also set the JNDI name on your JndiObjectFactory bean incorrectly. It needs to be java:comp/env/jdbc/myDataSource not jdbc/dataSource.

    You use a different name when you're looking up the resource versus when you registered it as the registration automatically places the resource beneath java:comp/env/.

提交回复
热议问题