- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
对于这个 JNDI 上下文命名问题,我已经阅读并尝试了大约 30 个 Google 和 StackExchange 结果,这让我发疯。
我正在尝试从 Wrox 工作书中获取一些源代码,该书简单地展示了使用 JNDI 数据源的 Hibernate 实体。
我收到以下错误:
javax.persistence.PersistenceException: Unable to build entity manager factory
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:83)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
com.wrox.site.EntityServlet.doGet(EntityServlet.java:82)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
root cause
org.hibernate.engine.jndi.JndiException: Unable to lookup JNDI name [java:comp/env/jdbc/EntityMappings]
org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:117)
org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115)
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
com.wrox.site.EntityServlet.doGet(EntityServlet.java:82)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
root cause
javax.naming.NameNotFoundException: Name [java:comp/env/jdbc/EntityMappings] is not bound in this Context. Unable to find [java:comp].
org.apache.naming.NamingContext.lookup(NamingContext.java:818)
org.apache.naming.NamingContext.lookup(NamingContext.java:152)
javax.naming.InitialContext.lookup(InitialContext.java:421)
org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:114)
org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115)
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
com.wrox.site.EntityServlet.doGet(EntityServlet.java:82)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
所以我尝试注释掉 EntityServlet.java 中构建 EntityManager 的行:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/EntityMappings");
Connection c = null;
c = ds.getConnection();
它一点也不提示。
知道到底发生了什么吗?
这是带有 Tomcat 8 的 Java 8。
网络/WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Entity Mappings Application</display-name>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspf</url-pattern>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>true</scripting-invalid>
<include-prelude>/WEB-INF/jsp/base.jspf</include-prelude>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
<default-content-type>text/html</default-content-type>
</jsp-property-group>
</jsp-config>
<session-config>
<session-timeout>30</session-timeout>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<distributable />
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/EntityMappings</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
web/META-INF/context.xml:
<Context>
<Resource name="jdbc/EntityMappings" type="javax.sql.DataSource"
maxActive="50" maxIdle="5" maxWait="10000"
username="***" password="***" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/EntityMappings"/>
</Context>
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wrox</groupId>
<artifactId>entity-mappings</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<log4j.version>2.0-rc1</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-taglib</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.2.0.Beta1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.5.Final</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<sourceDirectory>source/production/java</sourceDirectory>
<resources>
<resource>
<directory>source/production/resources</directory>
</resource>
</resources>
<testSourceDirectory>source/test/java</testSourceDirectory>
<testResources>
<testResource>
<directory>source/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>web</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
最佳答案
堆栈跟踪中的以下方法
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl( )
更改 TCCL(Thread.currentThread().getContextClassLoader())。
由于 Tomcat 中的 JNDI 由 webapp 的类加载器限定范围(因此不同的 web 应用程序具有不同的 JNDI 树),这会中断 JNDI 查找。
关于java - 未找到 JNDI 上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22926075/
我是 JNDI 的新手,我阅读了 oracle 的在线资料: http://docs.oracle.com/javase/jndi/tutorial/getStarted/overview/index
什么是JNDI? 它的基本用途是什么? 什么时候使用? 最佳答案 What is JNDI ? 它代表Java Naming and Directory Interface . What is its
我有完整的应用服务器背景,并考虑在 Jetty 等轻量级嵌入式服务器上运行应用。 我一直使用 JNDI 来查找连接池以查找数据库连接之类的东西,但我想知道这是否是轻量级案例的最佳方法。似乎如果我使用
您如何使用 JDBCRealm处理servlet 中的用户身份验证和授权?我能找到的唯一示例是在 web.xml 中创建数据源(例如 Authentication against database u
命名和目录 (JNDI) - 使用 JNDI 的陷阱是什么 最佳答案 这个问题有点含糊,但这里有几点需要考虑并且与 JNDI 相关。 JNDI 的好处是对象创建与对象查找分离 在 JDNI 中直接查找
在 Wildfly 9 中显示注册的 JNDI 名称的正确方法是什么? 对于旧版本,可以使用 /subsystem=naming:jndi-view ,但它似乎不再起作用。在域模式下运行时。 感谢帮助
我有两个 JBoss 服务器,JbossA 和 JbossB。每个都有自己的 JNDI。现在我在 JbossA 上有一个名为 jms/Client 的 JMS,在 JbossB 上有一个名为 jms/
这是我的“hibernate.cfg.xml”,我正在尝试连接到我的本地主机(postgres),但我不确定我是否输入了参数值(例如连接 url 或其他) : org.hiber
是否可以通过 JNDI 访问 Wildfly 属性(在 standalone.xml 中定义)? 喜欢: ... 并在java中阅读它: @Resource(lo
第126章OSGI Enterprise Release 5 specification提到兼容性: "Support the traditional JNDI programming model u
import org.apache.catalina.Context; import org.apache.catalina.deploy.ContextResource; import org.ap
在我们的项目中,我们使用 websphere liberty 服务器和 IBM MQ 作为消息服务器。我们在云中移动。我们想用 AWS SQS 替换 IBM MQ。在 server.xml 中,我们有
似乎每个人都说您应该使用 Tomcat 的 JNDI 上下文来管理您的 JDBC 连接和驱动程序等等。在阅读了文档之后,我理解了平局。但是,如果您使用它,您的应用程序必须从现在开始一直使用 Tomca
我正在 JBoss7.1.1 应用程序服务器上部署我的 MDB (EJB3.1)。当我使用@Resource进行数据源注入(inject)时,我使用全局JNDI引用名称(ENC +本地JNDI引用名称
使用 JBoss eap 6.4.12 出现错误: Error looking up ${email.jndi.lookup.binding} in JNDI 在我的 java 类中映射此 JNDI
使用com.sun.jndi.fscontext.RefFSContextFactory基于文件的 JNDI 上下文工厂,它似乎只允许在您指定的位置有 1 个绑定(bind)文件。例如 Hashtab
这是我的persistence.xml: org.hibernate.ejb.HibernatePersistence jdbc/abcDS 这是来自 src/test
我已经为我的模块之一运行了强化扫描,我已经收到了 动态代码评估:JNDI 引用注入(inject)漏洞问题 显示在下一行 lookup(dataSource) 数据源是动态的。我应该怎么做才能防止这种
我有 EJB 3.1 中的 EJB,我试图将其部署在 JBoss EAP 6 中,但是当我启动服务器时。它在 JNDI 名称中附加版本号,如下所示。 18:27:57,068 INFO [org.j
我有一个测试,它成功地使用嵌入式 glassfish 来测试 JCA 的部署。 但是,与已经在使用端口 3700 的 GlassFish 2.1 的运行版本存在冲突。 如何将嵌入的 GlassFish
我是一名优秀的程序员,十分优秀!