Tag: jndi

无法使用JBoss服务器实例化InitialContext

我正在尝试创建一个InitialContext所以我可以向JNDI询问一些企业java bean。 JBoss运行正常,但是当我运行java代码时,我得到了一个exception。 我正在运行JBoss 7.1 这是我的代码: public class Test { public static void main(String[] args){ InitialContext ctx=getInitialContext(); Object ref=null; try { ref = ctx.lookup(“ParamEJB/remote”); } catch (NamingException e) { System.out.println(“Lookup Failed”); e.printStackTrace(); } Param stub=(Param)PortableRemoteObject.narrow(ref, Param.class); int times=stub.getTimes(); for(int i=0;i<times;i++) System.out.println(stub.getMessage()); } public static InitialContext getInitialContext(){ Hashtable h=new Hashtable(); h.put(“java.naming.factory.initial”,”org.jnp.interfaces.NamingContextFactory”); h.put(“java.naming.provider.url”,”localhost”); try { return new […]

使用JNDI在Spring Boot中配置多个DataSource

我想使用您的Application Server内置function管理多个DataSource,并使用JNDI访问它。 我使用Spring JPA数据进行Spring启动。 我能够为单个数据源配置application.properties: – spring.datasource.jndi-name=jdbc/customers 我在context.xml文件中的配置如下: – 一切正常。 但是当我无法配置两个数据源时。 我确信在context.xml文件中的配置: – 我对application.properties文件配置有疑问。 我尝试了以下选项但没有成功: – spring.datasource.jndi-name=jdbc/customers,jdbc/employee 有关多个数据源的JNDI,请告诉我有关Spring启动的任何详细信息。 我好几天都在寻找这种配置。 任何forms的建议或评论都会受到高度赞赏。 根据Spring Boot文档进行第二次试用 spring.datasource.primary.jndi-name=jdbc/customer spring.datasource.secondary.jndi-name=jdbc/project 配置类。 @Bean @Primary @ConfigurationProperties(prefix=”datasource.primary”) public DataSource primaryDataSource() { return DataSourceBuilder.create().build(); } @Bean @ConfigurationProperties(prefix=”datasource.secondary”) public DataSource secondaryDataSource() { return DataSourceBuilder.create().build(); } 该应用程序无法启动。 虽然tomcat服务器正在启动。 日志中不会打印错误。 第三次试验: – 使用JndiObjectFactoryBean 我有以下application.properties spring.datasource.primary.expected-type=javax.sql.DataSource spring.datasource.primary.jndi-name=jdbc/customer spring.datasource.primary.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect spring.datasource.primary.jpa.show-sql=false […]

在glassfish命名中找不到SerialInitContextFactory

这个开始让我完全疯了…… 我想使用Maven创建一个Glassfish客户端应用程序。 为此,我添加了需要的gf-client依赖项: org.glassfish.appclient gf-client 3.1 pom compile 然后,想要联系我的Glassfish服务器,在同一个应用程序上运行,我会进行常规查找: Properties p = new Properties(); // optional. Defaults to localhost. Only needed if web server is running // on a different host than the appserver p.setProperty(“org.omg.CORBA.ORBInitialHost”, “localhost”); // optional. Defaults to 3700. Only needed if target orb port is not // 3700. p.setProperty(“org.omg.CORBA.ORBInitialPort”, “3700”); Context context […]

如何通过JNDI检索LDAP密码

我能够通过JNDI读取存储在LDAP中的密码。 但结果是一些胡言乱语的人物。 那我该怎么解密呢? 以下是我的代码: public static void main(String[] args) { String INITCTX = “com.sun.jndi.ldap.LdapCtxFactory”; String MY_HOST = “ldap://KhooGP-Comp1:1389”; String MGR_DN = “cn=Directory Manager”; String MGR_PW = “password”; String MY_SEARCHBASE = “dc=QuizPortal”; String MY_FILTER = “uid=yiwei”; String MY_ATTRS[] = {“cn”, “uid”, “sn”, “userpassword”}; //Identify service provider to use Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX); env.put(Context.PROVIDER_URL, […]

将Ldap用户与使用Java的组关联

我在找到如何将#Ldap用户与给定组关联时遇到问题。 这就是我尝试过的: Attributes attrs = new BasicAttributes(); BasicAttribute basicAttrs = new BasicAttribute(“objectclass”); basicAttrs.add(“top”); basicAttrs.add(“person”); BasicAttribute memberOf = new BasicAttribute(“memberOf”); memberOf.add(“Managers”); // Tried with distinguished name too memberOf.add(“Administrators”); // Tried with distinguished name too attrs.put(basicAttrs); attrs.put(“cn”, user.getLogin()); attrs.put(“name”, user.getLogin()); attrs.put(“login”, user.getLogin()); attrs.put(“mail”, user.getMail()); attrs.put(“displayName”, user.getDisplayName()); attrs.put(“memberOf”, memberOf); try { ctx.bind(“CN=” + user.getLogin() + “,” + baseDn, […]

spring jndi NamingException:名称未绑定在此Context中

我的春季3.2.4的webapp运行正常。 但是当我启动它时,我将获得调试信息: 2014-05-20 11:11:47 DEBUG JndiTemplate:150 – Looking up JNDI object with name [java:comp/env/spring.liveBeansView.mbeanDomain] 2014-05-20 11:11:47 DEBUG JndiLocatorDelegate:101 – Converted JNDI name [java:comp/env/spring.liveBeansView.mbeanDomain] not found – trying original name [spring.liveBeansView.mbeanDomain]. javax.naming.NameNotFoundException: Name [spring.liveBeansView.mbeanDomain] is not bound in this Context. Unable to find [spring.liveBeansView.mbeanDomain]. 2014-05-20 11:11:47 DEBUG JndiTemplate:150 – Looking up JNDI object with name [spring.liveBeansView.mbeanDomain] […]

通过JNDI使用ActiveMQ

我正在尝试使用JNDI创建与ActiveMQ的简单连接。 我有 队列名为’example.A’。 根据触及JNDI的ActiveMQ文档 ,如果我想通过JNDI使用ConectionFactories和Queues(Topics),我必须在我的类路径上放置jndi.properties文件。 据我所知,默认情况下,activeMQ类路径是%activemq%/ conf目录。 我没有改变它。 所以我的队列有这个属性: queue.MyQueue = example.A 我为ActiveMQ创建了java客户端类,它使用JNDI如下: Properties jndiParameters = new Properties() ; jndiParameters.put(Context.INITIAL_CONTEXT_FACTORY, “org.apache.activemq.jndi.ActiveMQInitialContextFactory”); jndiParameters.put(Context.PROVIDER_URL, “tcp://localhost:61616”); Context context = new InitialContext(jndiParameters); ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup(“ConnectionFactory”); Queue queue = (Queue) context.lookup(“MyQueue”); 但它找不到我的队列,它抛出exception:javax.naming.NameNotFoundException:MyQueue 我的错误在哪里?

Out容器JNDI数据源

我想在Java SE应用程序中使用JNDI配置DataSource。 做这个的最好方式是什么? 到目前为止,我遇到了两个项目: Apache命名 。 项目页面有一个用于配置数据源的特定示例,但看起来该项目已经超级旧并且不再处于活动状态。 JBossNS 。 看起来使用LocalOnlyContextFactory配置本地JNDI很容易,但我没有找到任何关于如何实际配置数据源的文档。 如果可能的话,我还想用JTA事务管理器配置数据源(使用JOTM?)。

“javax.naming.NoInitialContextException”是什么意思?

正如标题所暗示的那样,“javax.naming.NoInitialContextException”在非技术术语中意味着什么? 有什么一般建议来解决它? 编辑(从控制台): javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325) at javax.naming.InitialContext.lookup(InitialContext.java:392) at cepars.app.ConnectionHelper.getConnection(ConnectionHelper.java:25) at cepars.app.ConnectionHelper.getConnection(ConnectionHelper.java:10) at cepars.review.ReviewDAO.getJobList(ReviewDAO.java:30) at cepars.review.Test.main(Test.java:43) java.lang.NullPointerException at cepars.review.ReviewDAO.getJobList(ReviewDAO.java:31) at cepars.review.Test.main(Test.java:43) cepars.app.DAOException at cepars.review.ReviewDAO.getJobList(ReviewDAO.java:39) at cepars.review.Test.main(Test.java:43)

无法为连接URL”创建类”的JDBC驱动程序

我正在使用Tomcat 7.0.12并且每当我通过名为’ROOT’的webapp中的.jsp页面访问连接到postgresql数据库的JNDI数据源时都会收到此错误: SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.RuntimeException: Cannot create JDBC driver of class ” for connect URL ‘null’] with root cause java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507) at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476) at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307) at java.sql.DriverManager.getDriver(DriverManager.java:253) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) postgresql JDBC驱动程序位于我的CATALINA / lib文件夹中。 这是我的META-INF / context.xml: 这是我的WEB-INF / web.xml: ROOT […]