1.在tomcat下的server.xml的 <GlobalNamingResources> </GlobalNamingResources>添加下面代码

    <Resource name="jdbc/mysql" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/test"
username="root"
password=""
maxActive=""
maxIdle=""
maxWait="" />

2.在于server.xml同目录的context.xml中的<context></context>添加下代码

    <ResourceLink name="jdbc/mysql" type="javax.sql.DataSource" global="jdbc/mysql"/> 

3.web.xml中可加也可不加下边的代码

  <resource-ref>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>

4.spring的配置文件中添加下面代码

   <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/mysql</value>
</property>
</bean>

5.测试,在jsp中测试

<% Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/mysql");
Connection connection = ds.getConnection();
connection.close();
%>

spring配置JNDI(Java Naming and Directory Interface,Java命名和目录接口)数据源的更多相关文章

  1. JNDI(Java Naming and Directory Interface,Java命名和目录接口)

    JNDI(Java Naming and Directory Interface,Java命名和目录接口)是SUN公司提供的一种标准的Java命名系统接口,JNDI提供统一的客户端API,通过不同的访 ...

  2. J2EE学习从菜鸟变大鸟之四 JNDI(Java Naming and Directory Interface)

    掌握 J2EE 是件不是很轻松的事哈,但是很有意思,抽象抽象哈哈,因为它包含的技术和缩略语在不断地增长.Java 命名和目录接口(Java Naming and Directory Interface ...

  3. JNDI(Java Naming and Directory Interface)

    # 前言 内容基本拷贝,整理出来,方便以后回忆. # What The Java Naming and Directory Interface™ (JNDI) is an application pr ...

  4. Java Naming and Directory Interface (JNDI) Java 命名和目录接口

    https://www.oracle.com/technetwork/java/jndi/index.html Lesson: Overview of JNDI (The Java™ Tutorial ...

  5. 命名和目录接口 JNDI-The Java Naming and Directory Interface

    命名和目录接口 JNDI-The Java Naming and Directory Interface JNDI (The Java Naming and Directory Interface)为 ...

  6. 【JNDI】Java Naming and Directory Interface

    一.数据源的由来 在Java开发中,使用JDBC操作数据库的四个步骤如下:   ①加载数据库驱动程序(Class.forName("数据库驱动类");)   ②连接数据库(Conn ...

  7. Java命名和目录接口——JNDI

    JNDI即Java命名和目录接口(JavaNaming and Directory Interface),它属于J2EE规范范畴,是J2EE的核心技术之一,提供了一组接口.类和关于命名空间的概念.JD ...

  8. Spring配置JNDI的解决方案

    我的配置环境是:Spring + Tomcat + MySql 说明: 1. $TOMCAT_HOME代表Tomcat的安装目录. 第一步:在Tomcat的$TOMCAT_HOME/conf/cont ...

  9. Spring配置JNDI和通过JNDI获取DataSource

    一.SpringJNDI数据源配置信息 <bean id="dataSource" class="org.springframework.jndi.JndiObje ...

随机推荐

  1. android模拟器访问PC本地接口

    一般来讲PC本地接口是localhost:8080 而在安卓模拟器上用的话,他会映射模拟器本身的,也就是说,可以把模拟器也当成一个PC端来看待,这样会好理解点吧 而在模拟器上想要访问PC本地的loca ...

  2. MySql修改数据表的基本操作(DDL操作)

    1.查看数据库的基本语句:show databases; 2.选择相应的数据库进入语法:use 数据库名; 3.查看数据库中的表语法:show tables; 4.查看表的基本结构语句:desc 表名 ...

  3. Error:java: Annotation processing is not supported for module cycles. Please ensure that all modules from cycle [web_dao,web_service] are excluded from annotation processing

    早上学习maven环境搭建时遇到的这个问题 下面这个错误的大概意思是:模块之间的互相依赖 Error:java: Annotation processing is not supported for ...

  4. Python语言——基础01-环境安装、注释、变量

    开篇导言: 今天开始进行python学习的笔记更新,以后我都用截图的方式更新,方便不麻烦,界面美观,今天学习更新的python学习内容是环境安装.注释.变量的内容 关注我博客的童鞋从现在开始也可以跟着 ...

  5. springboot引入AOP

    AOP是Aspect Oriented Programming的缩写,意为面向切面编程.通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是spring框架的一个重要内容,她通过对 ...

  6. 架构设计---soa与msa的概念(转)

    https://blog.csdn.net/qq_15001229/article/details/79535037

  7. sitecore8.2 基于相对路径查询item

    当前项目: bar (path: /sitecore/content/home/foo/bar) 查询: query:./child/grandchild 结果: grandchild (path: ...

  8. sitecore 8.2 item属性查询

    查询: query:/sitecore/content/[@@templatename='Homepage'] 结果: home (name: home, path: /sitecore/conten ...

  9. Oracle免安装绿色版-PLSQL连接报12154

    在环境变量添加 TNS_ADMIN  值是你的免安装客户端中sqlnet.ora   tnsnames.ora 所在的目录 参考地址:https://blog.csdn.net/feng_na/art ...

  10. Oarcle之事务

    update:更新 例如转账: update emp_ temp set sal = sal-500 where ename = 'JONES':(更新表中sal项 为sal-500 是当ename= ...