jndi

Spring Jndi Context and PropertyPlaceholderConfigurer

北城以北 提交于 2019-11-29 10:39:29
Using Spring, I want to read a variable inside the context of Webspehere. Read a Environment Variable in Java with Websphere To define the data.... inside web.xml <env-entry> <env-entry-name>varName</env-entry-name> <env-entry-value>56</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry> To see with java Context envEntryContext = (Context) new InitialContext().lookup("java:comp/env"); String mydata = (String)envEntryContext.lookup(“varName”); But I want take the data in my common.xml like <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans

连接池(深入 J2EE 的连接合用)

不羁的心 提交于 2019-11-29 09:56:11
Java 2 Enterprise Edition (J2EE) 规范提供了实现高度可伸缩、可靠和可用的电子商务应用的分布式基于服务的体系结构。通常,J2EE 应用体系结构与模型-视图-控制器 (MVC) 框架相对应 -- 资源库/外部系统资源支持域模型(模型),JSP/Servlet 管理显示(视图),而 EJB 处理商业逻辑(控制器)。 通过服务器端所有三层中的组件实现一个典型的电子商务应用用例。考虑到用户交互数量的庞大(对于面对客户的应用,有上百万个),需要优化地共享有限的服务器端资源。这类资源可能包括数据库、消息队列、目录、企业系统 (SAP、CICS) 等等,它们中的每一个都可以由使用代表资源访问点的连接对象的应用来访问。管理对那些共享资源的访问对于满足 J2EE 应用的高性能需求来说至关重要。 连接合用是由数据库供应商倡导的技术,其目的是允许客户机共享一组高速缓存的连接对象,这些对象提供对数据库资源的访问。在本文中,我分析了 J2EE 环境中服务器端资源(例如数据库、消息队列、目录和企业系统)的连接合用。 为何合用资源连接? 考虑一下 代码示例 ,其中,EJB 使用 JDBC 1.0、 不使用 连接合用来访问数据库资源。 很明显,该示例的主要问题是连接的打开和关闭。考虑到实体 bean 是共享组件,因此,对每个客户机请求,都要进行几次获取和释放数据库连接的操作。 从图

Hinernate中获得数据库连接池的方式及应用

淺唱寂寞╮ 提交于 2019-11-29 09:55:46
Hibernate可以与任何一种java应用的运行环境集成。Java应用的运行环境可分为两种。 (1)受管理环境(Managed environment):由容器负责管理各种共享资源(如线程池和数据库连接池),以及管理事务和安全。如JBoss、WebLogic和WebSphere等J2EE应用服务器都提供了符合J2EE规范的受管理环境。 (2)不受管理环境(Non-managed environment):由应用本身负责管理数据库连接、定义事务边界以及管理安全。独立的桌面应用或命令行应用都运行在不受管理环境中。Servlet容器会负责管理线程池,如tomcat容器还会管理数据库连接池,但是Servlet容器不会管理事务,因此它提供的仍然是不受管理的运行环境。 Hinernate中获得数据库连接池的方式 1.使用默认的数据库连接池   Hibernate提供了默认的连接池实现,实现类为DriverManagerConnectionProvider。如在Hibernate配置文件中没有明确配置任何连接池,就会使用这个默认的连接池。   默认连接池的hibernate.properties文件   Hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect   Hibernate.connection.driver_class=com

Getting org.hibernate.exception.JDBCConnectionException: could not execute query even through JNDI

柔情痞子 提交于 2019-11-29 08:47:40
I use Struts2+JSP+Tomcat6+Hibernate+Mysql as my J2EE application framework.Following to this topic, I've had the problem of getting this error: org.hibernate.exception.JDBCConnectionException: could not execute query It appears to be due to the fact that mysql closes it's connections after n hours. As people answered there I changed the hibernate config to get my db connections through JNDI.here is the course of actions which I've taken to do this: my hibernate.cfg.xml: <hibernate-configuration> <session-factory> <property name="connection.datasource">java:comp/env/jdbc/hposg</property>

Junit Testing JNDI InitialContext outside the application server

落爺英雄遲暮 提交于 2019-11-29 06:46:45
问题 Context context = new InitialContext(); dataSource = (DataSource) context.lookup("java:comp/env/jdbc/multiDS"); connection = dataSource.getConnection(); Please help me to mock the above code. Hi Tom Anderson I tried the below code @BeforeClass public static void setUpClass() throws Exception { // rcarver - setup the jndi context and the datasource try { // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System

JNDI是什么?

允我心安 提交于 2019-11-29 06:44:47
概念 JNDI(Java Naming and Directory Interface ),类似于在一个中心注册一个东西,以后要用的时候,只需要根据名字去注册中心查找,注册中心返回你要的东西。web程序,我们可以将一些东西(比如数据库相关的)交给服务器软件去配置和管理(有全局配置和单个web程序的配置),在程序代码中只要通过名称查找就能得到我们注册的东西,而且如果注册的东西有变,比如更换了数据库,我们只需要修改注册信息,名称不改,因此代码也不需要修改。 String jndiName= ...; Context context = new InitialContext(); DataSource ds = (DataSourse)context.lookup(jndiName); 由来 JNDI总结 在Java开发中,使用JDBC操作数据库的四个步骤如下:   ①加载数据库驱动程序(Class.forName("数据库驱动类");)   ②连接数据库(Connection con = DriverManager.getConnection();)   ③操作数据库(PreparedStatement stat = con.prepareStatement(sql);stat.executeQuery();)   ④关闭数据库,释放连接(con.close();) 也就是说

javax.naming.CommunicationException: simple bind failed

前提是你 提交于 2019-11-29 06:20:57
问题 When trying to connect to the LDAP server using a simple LDAP application I am getting an error which says "simple bind failed". I am assuming this is related to some sort of BIND. I have a bind property in one of the property file for a different application, but am not sure how to pass on that property to this program. Do I need to add any further details? Code import javax.naming.directory.*; import javax.naming.*; import java.util.Vector; import java.util.Enumeration; import java.util

设计模式之服务定位器模式

依然范特西╮ 提交于 2019-11-29 05:42:59
1.简介 菜鸟教程 中: 服务定位器模式(Service Locator Pattern)用在我们想使用 JNDI 查询定位各种服务的时候。考虑到为某个服务查找 JNDI 的代价很高, 服务定位器模式充分利用了缓存技术 。在首次请求某个服务时, 服务定位器在 JNDI 中查找服务,并缓存该服务对象 。当再次请求相同的服务时,服务定位器会在它的缓存中查找,这样可以在很大程度上提高应用程序的性能。以下是这种设计模式的实体。 服务(Service) - 实际处理请求的服务。对这种服务的引用可以在 JNDI 服务器中查找到。 Context / 初始的 Context - JNDI Context 带有对要查找的服务的引用。 服务定位器(Service Locator) - 服务定位器是通过 JNDI 查找和缓存服务来获取服务的单点接触。 缓存(Cache) - 缓存存储服务的引用,以便复用它们。 客户端(Client) - Client 是通过 ServiceLocator 调用服务的对象。 通过当前的服务定位器中的serviceLocator中获得服务资源,使用特定的词获得特定的service,(缓存中存在返回缓存数据,否者使用initContext获取service) 2.例子 模拟资源的查找 3.创建接口 Service 中的内容: /** * @description 服务接口

Problems using eclipse Hibernate plugin - could not locate sessionfactory in JNDI

人盡茶涼 提交于 2019-11-29 05:06:40
I'm using the reverse engineering capabilities built into the eclipse hibernate plugin to generate dao's and hbm.xml files for each table. It does it quite well but when I try to use the generated Objects I get a Could not locate SessionFactory in JNDI error. I saw a post that suggested this happens when you name your SessionFactory in the hibernate.cfg.xml file so I removed the name tag and i'm still getting the same error. This is my hibernate.cfg.xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http:/

How to activemq in ssl

心已入冬 提交于 2019-11-29 02:28:25
I'm trying to send messages via jms (activemq) but I want it to be in ssl protocol. It actuality works in tcp for now. I use jndi, with a virtual topic and 2 queues. Could somebody help me, I tryed this but I get stuck the server won't start : http://activemq.apache.org/how-do-i-use-ssl.html thx edit : The log says : "The reference to entity "needClientAuth" must end with the ';' delimiter." I will answer my own question : First of all inside ..../apache-activemq-5.11.1/conf/activemq.xml : <transportConnectors> <transportConnector name="ssl" uri="ssl://0.0.0.0:61617?trace=true&needClientAuth