在centos7上为Jetty配置c3p0-mysql连接池.

来源:互联网 发布:北京现代软件学院骗局 编辑:程序博客网 时间:2024/06/15 11:34

一共需要改三处:

  1. 修改Jetty的配置文件.
  2. 修改项目的web.xml使依赖c3p0连接池.
  3. 配置好环境.

进入正题:
首先下载安装Jetty.
然后修改 JETTY_HOME/etc/jetty.xml文件追加如下内容:

<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">     <Arg></Arg>     <Arg>jdbc/DSTest</Arg>     <Arg>      <New class="com.mchange.v2.c3p0.ComboPooledDataSource">         <Set name="driverClass">com.mysql.jdbc.Driver</Set>         <Set name="jdbcUrl">jdbc:mysql://localhost:3306/mysql</Set>         <Set name="user">root</Set>         <Set name="password">123456</Set>      </New>     </Arg></New>

然后修改项目里的web.xml,追加代码:

<resource-ref>     <description>My DataSource Reference</description>     <res-ref-name>jdbc/DSTest</res-ref-name>     <res-type>javax.sql.DataSource</res-type>     <res-auth>Container</res-auth></resource-ref>

两个xml文件都修改了,然后应该配置运行时的环境:

安装mysql,刚安装完时不需要用户名密码直接输入

[root@centos7 etc]#  mysql

然后为root用户添加一个123456的密码:

use mysql;update user set password=PASSWORD("123456") where user='root';

mysql已经配置完了,然后应该将需要的jar包放在jetty服务器上:

//切换到jetty依赖的扩展包的所在的文件夹.[root@centos7 etc]# cd JETTY_HOME/lib/ext//下载c3p0需要依赖的jar包.[root@centos7 etc]# wget http://repo1.maven.org/maven2/c3p0/c3p0/0.9.1.2/c3p0-0.9.1.2.jar//然后你需要将一个mysql驱动包也拷贝到此文件夹.比如 mysql-connector-java-3.1.12-bin.jar
**然后将war包放入jetty的webapps里面.**

现在只需要重启jetty服务器就可以了.
重启jetty可以使用:

[root@centos7 etc]# cd JETTY_HOME/bin[root@centos7 etc]# ./jetty.sh stop[root@centos7 etc]# ./jetty.sh -d start

如果想确认可以使用jconsole.exe查看信息.

原创粉丝点击