IDEA社区版中maven-tomcat插件配置JNDI数据源
来源:互联网 发布:mac 查看应用程序路径 编辑:程序博客网 时间:2024/05/16 18:41
前言:
由于在学习过程中,教程是使用eplices进行的,而我自己是使用IDEA,所以把配置过程记录下来
运行环境:OSX 10 、IDEA社区版、Java8、mysql 5.1.38、tomcat7-maven-plugin
步骤:
在Web项目的WEB-INF文件夹中创建context.xml,内容如下
<!-- context.xml --><?xml version="1.0" encoding='UTF-8' ?><context> <WatchedResource>WEB-INF/web.xml</WatchedResouurce> <Resource name="jdbc/msg" auto="container" type="javax.sql.DataSource" username="root" password="Hh13532550193!" driverClassName="com.mysql.jdbc.Driver" maxActive="20" maxIdle="20" /> </context>
在项目的pom.xml文件中的tomcat7的依赖配置中添加context.xml文件的路径,以便Tomcat7能正确引用该文件:
<!-- pom.xml --><build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> .... .... <configuration> ... <contextFile>context.xml文件的路径</contextFile> </configuration> .... </plugin> </plugins></build>
在web.xml中声明
<!-- web.xml --><resource-ref> <res-ref-name>jdbc/msg</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth></resource-ref>
在java代码中获取数据库链接:
import javax.naming.Context;import javax.naming.InitialContext;import javax.sql.DataSource;import java.sql.*;.....Context initCtx = new InitialContext();Context envCtx = (Context) initCtx.lookup("java:comp/env");DataSource ds = (DataSource)envctx.lookup("jdbc/msg");Connection conn = ds.getConnection();
0 0
- IDEA社区版中maven-tomcat插件配置JNDI数据源
- IDEA社区版中maven-tomcat插件配置JNDI数据源
- 社区版idea 基于maven配置tomcat
- Tomcat中配置JNDI数据源
- tomcat中通过JNDI数据源配置使用
- tomcat中通过JNDI数据源配置使用
- 在Tomcat 6 中配置JNDI数据源
- tomcat中通过JNDI数据源配置使用
- 在tomcat中配置JNDI数据源
- tomcat中通过JNDI数据源配置使用
- 在tomcat中配置JNDI数据源
- jndi查找数据源,配置tomcat中
- 如何在Tomcat中配置JNDI数据源
- Tomcat中配置JNDI数据源详解
- tomcat JNDI数据源配置
- Tomcat 配置JNDI 数据源
- tomcat JNDI数据源配置
- Tomcat配置JNDI数据源
- java的访问控制权限
- 杭电1297-用string
- 理解HTTP消息头 (三)
- 第二周的Android学习
- mysql 详细安装步骤
- IDEA社区版中maven-tomcat插件配置JNDI数据源
- 解决mysql的1045错误,让别人可以远程自己的数据库
- 当谈论工程师文化时我们在谈些什么
- 字符串格式转换
- 记负均正
- 2016年3月13日星期日下午
- 多线程 : 线程池的基本用法
- byte[]和InputStream的相互转换
- Android PDF开发:android-pdfview