Jetty uses the jndi data source, jettyjndi

Source: Internet
Author: User

Jetty uses the jndi data source, jettyjndi

Previously, the normal data source of the Project was switched to the jndi access form (that is, c3p0 was installed in the jboss data connection pool in the form of mbean ),

For the jetty server used for local testing, in order to unify the database access, I also found the configuration method of the jndi data source provided by jetty, which is as follows:

 

1. Create jetty. xml in the project path and the default configuration file jetty. Add the following content to the server:

<Configure id = "Server" class = "org. eclipse. jetty. server. Server">
<New id = "scmsDs" class = "org. eclipse. jetty. plus. jndi. Resource">
<Arg> </Arg>

<! -- Jndiname -->
<Arg> java: scmsDS </Arg>
<Arg>
<New class = "com. mchange. v2.c3p0. ComboPooledDataSource">
<Set name = "driverClass" >$ {jdbc. driverClassName} </Set>
<Set name = "jdbcUrl" >$ {jdbc. url} </Set>
<Set name = "user" >$ {jdbc. username} </Set>
<Set name = "password" >$ {jdbc. password} </Set>
</New>

</Arg>

<! -- New... another jndi datasource pool -->

</Configure>

As shown above, the simplest configuration is to define a jndiname and a c3p0 connection pool. jetty also supports configuring multiple connection pools.

2. Configure jetty to load jetty. xml at jetty startup

Our project starts jetty in the form of maven plug-in. Other forms should be similar.

Note that datasouce must be dependent on the c3p0 and jdbc drivers. If the project does not have these dependencies

Special statement. As follows:

<Plugin>
<GroupId> org. mortbay. jetty </groupId>
<ArtifactId> jetty-maven-plugin </artifactId>
<Version> 8.1.2.v20120308 </version>
<Dependencies>
<Dependency>
<GroupId> c3p0 </groupId>
<ArtifactId> c3p0 </artifactId>
<Version> 0.9.1.2 </version>
</Dependency>
<Dependency>
<GroupId> com. oracle. jdbc </groupId>
<ArtifactId> ojdbc5 </artifactId>
<Version> 11.2.0.3 </version>
</Dependency>
</Dependencies>
<Configuration>
<JettyXml >$ {project. build. outputDirectory}/jetty. xml </jettyXml>
<! -- Other configuration -->
</Configuration>
</Plugin>

3. Use the data source in the project

Like all the jndi services, if a framework is used, such as the spring framework, let spring Help You With lookup:

<Bean id = "dataSource" class = "org. springframework. jndi. JndiObjectFactoryBean">
<Property name = "jndiName" value = "java: scmsDS"/>
</Bean>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.