jndi

使用分层实现业务处理

匿名 (未验证) 提交于 2019-12-03 00:22:01
JNDI简介 JNDI的全称是Java命名与目录接口(Java Naming and Directory Interface),是一个有关应用程序设计的API,为开发人员提供了查找和访问各种命名与目录服务的通用,统一的接口。 通过名称将资源与服务进行关联。 JNDI的作用与优点 1、在应用与Java对象或资源之间建立松耦合的逻辑关联,简化应用对于资源的配置及维护工作 2、可以在更大范围、不同应用之间共享资源 JNDI的简单应用 Tomcat\conf\context.xml文件 <Context> <Environment name="tjndi" value="hello JNDI" type="java.lang.String" /> </Context> <Environment>元素用于配置命名的值,所配置的值作为环境条目资源,对整个Web应用可见,它包含的属性有name,type,value。 name:环境条目的名称,相对于java:comp/env的名称。 type:环境条目的Java类名的全称。 value:通过JNDI context请求时,返回给应用的参数值,该值必须转换成type属性定义的Java类型。 lookup()进行查找 // javax.naming.Context提供了查找JNDI 的接口 Context ctx = new

How to configure JDBCRealm to obtain its DataSource from JNDI

百般思念 提交于 2019-12-02 22:48:42
How do you use a JDBCRealm to handle authenticating and authorizing users in servlets? The only example I can find is to create the DataSource in web.xml (such as Authentication against database using shiro 1.2.1 ). I do not want to include database credentials in my source tree (for obvious reasons) and would prefer to use a Context defined DataSource via JNDI as I have for every other RDBMS I have used for any other purpose in every other servlet project I have developed. How do you configure a Shiro JDBCRealm to obtain its DataSource from JNDI? Les Hazlewood Vrushank's answer was really

How to store string values in context.xml

a 夏天 提交于 2019-12-02 22:21:31
I'd like to store connection URLs in a JNDI binding for my Tomcat application. Since Tomcat uses context.xml for JNDI resource defining, I need to figure out the propert way to store a String (or multiple strings for multiple connections) in context.xml . My reason for doing this is so that I can define different strings for different environments, and load them through JNDI. Usually, I see entries like so: <Context ...> <Resource name="someName" auth="Container" type="someFullyQualifiedClassName" description="Some description."/> </Context> Is it really just as simple as: <Context ...>

Mysql not reconnecting with JNDI Tomcat 6

最后都变了- 提交于 2019-12-02 21:20:45
I am using JNDI with Tomcat6 to manage Mysql connections, my Catalina/domain.com/ROOT.xml has: <Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource" username="db1" password="somepass" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/db?autoReconnect=true" maxActive="15" maxIdle="3" maxWait="5000" removeAbandoned="true" removeAbandonedTimeout="20" /> I though autoReconnect will do the job reconnecting to database but it does not, after about 8 hours of inactivity my app spits out lost connection to database errors. Any ideas? Thanks, Fedor Dont use

Understanding JNDI

别等时光非礼了梦想. 提交于 2019-12-02 20:29:30
JNDI is like a map on steroids right? I use a key to find references to objects. Also, what is InitialContext? I don't seem to get the idea. Conceptually, JNDI is like System.getProperties() on steroids. System.getProperties() allows you to pass String parameters to your code from the command line. Similarly, JNDI allows you to configure arbitrary objects outside of your code (for example, in application server config files) and then use them in your code. In other words, it's an implementation of Service Locator pattern : your code obtains services configured by environment from the centeral

JNDI No EJB receiver available for handling

大城市里の小女人 提交于 2019-12-02 20:04:45
问题 I have a problem with my EJBTest. I have installed WildFly and configured user management and application management. I wrote an EJB 3.0 and deployed it: @Stateless @Remote(NewSessionBeanRemote.class) public class NewSessionBean implements NewSessionBeanRemote { List<String> bookShielf; /** * Default constructor. */ public NewSessionBean() { bookShielf = new ArrayList<String>(); } @Override public void addBook(String bookName) { bookShielf.add(bookName); } @Override public List getBook() {

Adding custom object to JNDI on Weblogic 10

廉价感情. 提交于 2019-12-02 19:38:10
Is it possible to add a custom object (String or URL) to JNDI using Weblogic Server Administration Console (Weblogic 10.0) or by editing server's configuration file (config.xml)? I don't think so. Quoting Load objects in the JNDI tree : Using the Administration Console, you can load WebLogic Server J2EE services and components, such as RMI, JMS, EJBs, and JDBC Data Sources, in the JNDI tree. And indeed, I couldn't find a way to add a String or URL using the console. AFAIK, the standard way is to put an env-entry in your deployment descriptor (web.xml, ejb-jar.xml): <env-entry> <env-entry-name

javax.naming.NoInitialContextException with mysql DataSource

可紊 提交于 2019-12-02 19:33:11
问题 Trying to connect to a MySQL database MysqlDataSource mysqlDs = new MysqlDataSource(); Properties prop = new Properties(); String mysqlDataSourceDriver = "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"; Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, mysqlDataSourceDriver); properties.put(Context.PROVIDER_URL , "jdbc:mysql://localhost:3306/database"); Context ctx = new InitialContext(prop); ctx.bind("jdbc/wczasy", mysqlDs); And the stacktrace: javax

severlet容器中的JNDI引发的思考

时光毁灭记忆、已成空白 提交于 2019-12-02 19:15:57
最近一个小朋友,问了我一个急剧郁闷的问题,java平台开发的一个问卷调查系统,源代码是基于SQLSERVER2000的,现在换成2005怎么弄,还把代码传过来让我帮忙改,我拒绝,这需要改代码吗?2000和2005的JDBC驱动包都一样的怎么会需要改呢?我问报什么错,说can’t classload :。。。。一看就知道没找到驱动包,我说你把驱动包加上去,小伙说还错,我火大了,远程一看我无语了,他们用的是JNDI方式,小伙加死了 WEB-INF/lib 下面的驱动这辈子也起不来服务。 最后让他把驱动加入到tomcat/lib下面,才OK。小伙号称学习JAVA一年之久。已经知道JDBC怎么回事情,知道J2EE架构,我晕啊。我后来说你这个是JNDI方式的数据连接,驱动要放到容器项目的LIB下面,一脸茫然,我说tomcat是一个实现servlet的容器你知道不?一脸茫然。他来已经项目下面的不都是放到WEB-INF/lib下面吗?是啊,你说的没错,可是你现在用的是容器上面的服务资源,你的数据库连接资源(DateSource)是在容器上面提供的,所以相当于JDBC的连接程序在容器级别。还是一脸茫然。。。于是乎我有冲动把全部的severlet容器和web项目的关系和他说一边。结果小伙来一句“我想放弃JAVA。。。。”现在的孩子为什么没有一个完整系统的学习和研究的过程啊。。。。 来源:

How to get resource from the context.xml file in tomcat webapp?

泄露秘密 提交于 2019-12-02 17:43:17
This is my context.xml file: ... <Resource auth="Container" driverClass="net.sourceforge.jtds.jdbc.Driver" type="com.jolbox.bonecp.BoneCPDataSource" idleMaxAge="240" idleConnectionTestPeriod="60" partitionCount="3" acquireIncrement="1" maxConnectionsPerPartition="10" minConnectionsPerPartition="3" statementsCacheSize="50" releaseHelperThreads="4" name="jdbc/MyDatasource" username="my_username" password="my_password" factory="org.apache.naming.factory.BeanFactory" jdbcUrl="jdbc:jtds:sqlserver://localhost:12345/my_database" /> ... I already tried using ServletContext.getResource(java.lang.String