1.配置jetty连接池
在webapp/WEB-INF下创建jetty的环境配置文件jetty-env.xml,jetty启动时从该文件读取配置并配置jetty,配置postgres连接池的jetty-env.xml范例如下:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="postgresDb" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/postgres</Arg>
<Arg>
<New class="org.postgresql.ds.PGPoolingDataSource">
<Set name="serverName">db_host</Set>
<Set name="databaseName">db_name</Set>
<Set name="user">db_user</Set>
<Set name="password">password</Set>
</New>
</Arg>
</New>
</Configure>
2.在Spring中使用上面定义的JNDI数据源
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" destroy-method="close">
<property name="jndiName">
<value>java:comp/env/jdbc/postgres</value>
</property>
</bean>
本文介绍如何在Jetty中配置PostgreSQL连接池,并通过Spring框架使用此连接池进行数据库操作。首先,在webapp/WEB-INF目录下创建jetty-env.xml文件来设置连接池参数;其次,在Spring配置文件中通过JNDI数据源引用已配置的数据源。
6159

被折叠的 条评论
为什么被折叠?



