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>