jndi

WildFly JNDI lookup for local EJB deployed in a WAR

馋奶兔 提交于 2019-11-28 14:14:32
I'm using WildFly 8.1.0 Final release. My application is a JavaEE web app deployed in a WAR (there is no EJB module .ear). I want to programmatically invoke local EJB with his name using JNDI. The EJB are just annotated with @Stateless (there is no Local or Remote interfaces) I try below function: private <E extends DomainObject> CrudService<E> lookUp(Class<E> cl) { try { final Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); final Context context = new InitialContext(jndiProperties); // The app name is the application

simple string value by JNDI in Java

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 13:22:22
问题 How can i set simple string value in configuration of tomcat and then read in java application? context.xml <ResourceLink name="global/test" global="testing" type="java.lang.String" /> server.xml <Enviroment name="testing" value="myUser" type="java.lang.String"/> web.xml in application <resource-env-ref> <resource-env-ref-name>global/test</resource-env-ref-name> <resource-env-ref-type>java.lang.String</resource-env-ref-type> </resource-env-ref> in my java application public String getValue(){

Deploying a war to Jetty with CDI

不问归期 提交于 2019-11-28 13:06:52
I have a maven project in IntelliJ where I am trying to deploy a war file to a jetty container. The purpose of this is for a quick integration test of some of the functionality in said war file. Since out of the box Jetty does not come with CDI or JNDI, I am trying to add support for these but running into some issues. For example, I get the following error on startup: 15:30:50 [34mINFO [0;39m o.a.s.c.CdiObjectFactory - [lookup]: Checking for BeanManager under JNDI key java:comp/BeanManager 15:30:50 [39mDEBUG[0;39m o.a.s.c.CdiObjectFactory - [lookup]: BeanManager lookup failed for JNDI key

Using a JNDI datasource created by another application with Tomcat

别来无恙 提交于 2019-11-28 11:44:51
I have a .properties file in my application which contains dataSource properties. I set up a JNDI reference to this dataSource using the following code : // first I create MyDataSource from the properties found in the .properties file //then : Context initContext = new InitialContext(); initContext.createSubcontext("jdbc"); initContext.createSubcontext("jdbc/oracle"); initContext.rebind(jdbc/oracle/myDataSource, MyDataSource); If I use a lookup in this application, the dataSource is found : Context initContext = new InitialContext(); BasicDataSource dataSource = (BasicDataSource) initContext

Inject a file using @Resource and JNDI in JEE6

拥有回忆 提交于 2019-11-28 10:20:14
问题 Is it possible to inject a file using JNDI and @Resource in JEE6? If so how do I setup and JNDI (file) resource in Glassfish? 回答1: If your objective is to configure a properties file as follows: @Inject @Resource("META-INF/aws.properties") Properties awsProperties; then you want to use a WELD extension which is explained in the WELD documentation here It is as simple as adding this to your POM <dependency> <groupId>org.jboss.weld</groupId> <artifactId>weld-extensions</artifactId> <version>$

Junit Testing JNDI InitialContext outside the application server

久未见 提交于 2019-11-28 08:17:54
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.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); Context ic = new InitialContext(); ic

Declaring @Resource and @EJB at the class level in Java EE6

蓝咒 提交于 2019-11-28 07:53:10
Is there any situation still ( given that Java EE6 has java:global/, app/, module/ naming standards) that necessitates declaring EJBs or Resources like the example below? @EJB (name = "ejb/PlaceBid", beanInterface = PlaceBid.class) public class ActionBazaarBidControllerServlet extends HttpServlet { } Looking up PlaceBid in the helper class used by ActionBazaarBidControllerServlet PlaceBid placeBid = (PlaceBid)context.lookup("java:comp/env/ejb/PlaceBid"); The java:comp/env/ namespace is sometimes a little understood feature. This namespace corresponds to what is called the Enterprise Naming

三种数据库连接池的配置及使用(For JDBC)

牧云@^-^@ 提交于 2019-11-28 05:03:28
连接池的优缺点 优点 使用连接池的最主要的优点是性能。创建一个新的数据库连接所耗费的时间主要取决于网络的速 度以及应用程序和数据库服务器的 ( 网络 ) 距离,而且这个过程通常是一个很耗时的过程。而采用 数据库连接池后,数据库连接请求可以直接通过连接池满足而不需要为该请求重新连接、认证到 数据库服务器,这样就节省了时间。 缺点 数据库连接池中可能存在着多个没有被使用的连接一直连接着数据库 ( 这意味着资源的浪费 ) 。 DBCP 一、导包 Apache官网下载DBCP包,导入两个包路径如下: commons-dbcp-1.4-bin\commons-dbcp-1.4\commons-dbcp-1.4.jar:连接池的实现 commons-pool-1.5.6-bin\commons-pool-1.5.6\commons-pool-1.5.6.jar:连接池实现的依赖库 CSDN上jar包的下载地址:http://download.csdn.net/detail/u012802702/9491642 二、代码示例: 方式一:使用BasicDataSource 通过方法设置连接参数。 [java] view plain copy //获取BasicDataSource并配置,开始.... BasicDataSource source = new BasicDataSource();

Using dynamic Datasource with Tomcat

前提是你 提交于 2019-11-28 04:48:10
问题 I'm creating a series of webservices for my application and i have the need to access a different database based on the serviceCode that is passed as a parameter in the webservice call. I setup a basic resource with tomcat to access a database like this <Resource name="jdbc/db_name" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="user" password="pass" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://server_ip:3306/db_name"/> But in

How do I connect to a Websphere Datasource with a given JNDI name?

拥有回忆 提交于 2019-11-28 04:24:16
I'm using Websphere Portal 7.0 and creating a portlet with RAD 8.0. My portlet is trying to make a db2 connection to a remote server. I wrote a java program locally to do a basic JDBC connection to the server and get records from a table. The code works fine; however, when I add the code to my portlet as well as the db2jcc4.jar, the connection doesn't work. I'm using the basic: Connection connection = DriverManager.getConnection("jdbc:db2://server:port/db:user=user;password=pw;"); I figure that using the Websphere datasource is the right way to go. I know the JNDI name for the datasource, but