cike0415 发表于 2017-2-27 09:33:44

jetty 配置jndi数据源(Postgres连接池),Spring中使用

  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>
页: [1]
查看完整版本: jetty 配置jndi数据源(Postgres连接池),Spring中使用