Skip to content

Commit

Permalink
Merge branch 'jersey-weld-cdi'
Browse files Browse the repository at this point in the history
  • Loading branch information
criztovyl committed Jun 21, 2017
2 parents bdd1060 + f906f4b commit 13a150e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ Method | URL
`{kid}`| Klassen ID
`{did}`| Disziplin ID
`{eid}`| Ergebnis ID

## MySQL Database connection

Download MySQL Driver and put into `$CATALINA_BASE/lib`: [MySQL Connector/J](https://dev.mysql.com/downloads/connector/j/).

Add this to `$CATALINA_BASE/conf/context.xml` (replace `USER`, `PASSWORD`, `HOST` and `DATABASE`):

<Resource name="jdbc/sportfest" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
username="USER" password="PASSWORD" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://HOST:3306/DATABASE"/>

See also [Tomcat JNDI Resources How-To](https://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html#JDBC_Data_Sources), [JNDI Resources Examples (MySQL)](https://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html#MySQL_DBCP_Example).
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ dependencies {
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.26-b03'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.26-b03'

// CDI Integration for @Resource in Jersey Resources
compile 'org.jboss.weld.servlet:weld-servlet:2.2.15.Final'
compile 'org.glassfish.jersey.ext.cdi:jersey-weld2-se:2.26-b03'

providedCompile 'javax.servlet:servlet-api:2.5'
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/atiw/sportfest/backend/resource/TestResource.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package de.atiw.sportfest.backend.resource;

import javax.annotation.Resource;
import javax.sql.DataSource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/test")
public class TestResource {

@Resource(name="jdbc/sportfest")
DataSource db;

@GET
@Path("cdi")
public String getStatus(){
return db != null ? "CDI works!" : "CDI is broken!";
}

@GET
public String getPlainText(){
return "Hello world!";
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@
<url-pattern>/*</url-pattern>
</servlet-mapping>

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/sportfest</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

</web-app>

0 comments on commit 13a150e

Please sign in to comment.