Skip to content

Commit e382de0

Browse files
committed
📝 Add an example project for Jersey & Spring DI
1 parent fae873f commit e382de0

File tree

16 files changed

+654
-1
lines changed

16 files changed

+654
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Documents
114114
- [Java standard RESTful web services with Jersey](http://nginx-clojure.github.io/more.html#user-content-39--java-standard-restful-web-services-with-jersey)
115115
- [Embeding Tomcat](http://nginx-clojure.github.io/more.html#user-content-310-embeding-tomcat)
116116
- [Use Spring Framework with Nginx-Clojure Java Handlers](https://github.com/nginx-clojure/nginx-clojure/tree/master/example-projects/spring-core-example)
117+
- [Example Project about Jersey & Spring with Nginx-Clojure](https://github.com/nginx-clojure/nginx-clojure/tree/master/example-projects/jersey-spring-example)
117118
- [More about Nginx Worker Process](http://nginx-clojure.github.io/more.html#user-content-311-more-about-nginx-worker-process)
118119
- [More about Nginx-Clojure](http://nginx-clojure.github.io/more.html)
119120
- [Directives Reference](http://nginx-clojure.github.io/directives.html)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
/.classpath
3+
/.project
4+
/.settings
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Jersey & Spring Example for Nginx-Clojure
2+
3+
This example project is used to demo how to use jersey, a JAX-RS Reference Implementation,
4+
and spring dependency injection with Nginx-Clojure
5+
6+
.
7+
8+
## Run Unit Test
9+
10+
[source,shell]
11+
....
12+
mvn test
13+
....
14+
15+
16+
17+
## Run Application
18+
19+
.Get the source
20+
[source,bash]
21+
....
22+
git clone https://github.com/nginx-clojure/nginx-clojure
23+
....
24+
25+
.Package
26+
[source,bash]
27+
....
28+
cd nginx-clojure/example-projects/jersey-spring-example
29+
## use mvn pakage to get jersey-spring-example-0.0.1-jar-with-dependencies.jar
30+
mvn package
31+
....
32+
33+
.Download Nginx-Clojure
34+
[source,bash]
35+
....
36+
cd nginx-work-dir
37+
mkdir logs temp
38+
wget https://sourceforge.net/projects/nginx-clojure/files/nginx-clojure-0.5.1.tar.gz
39+
tar -zxvf nginx-clojure-0.5.1.tar.gz nginx-clojure-0.5.1/nginx-linux-x64
40+
mv nginx-clojure-0.5.1/nginx-linux-x64 nginx
41+
....
42+
43+
.Run Nginx-Clojure
44+
[source,bash]
45+
....
46+
./nginx
47+
....
48+
49+
.Add a student
50+
[source,bash]
51+
....
52+
curl -H "Content-Type: application/json" -X POST -d '{"name":"Tom", "grade":"A"}' http://localhost:8080/api/students
53+
....
54+
55+
56+
.Find student by id
57+
[source,bash]
58+
....
59+
curl http://localhost:8080/api/students/1
60+
....
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
logs
2+
/nginx
3+
temp
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<configuration debug="false">
2+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
3+
<encoder>
4+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %-10contextName %logger{36} - %msg%n</pattern>
5+
</encoder>
6+
</appender>
7+
8+
9+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
10+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
11+
<!-- daily rollover -->
12+
<fileNamePattern>logs/clojure-web-example-%d{yyyy-MM-dd}-${MY_PNO}.log</fileNamePattern>
13+
<!-- keep 30 days' worth of history -->
14+
<maxHistory>30</maxHistory>
15+
</rollingPolicy>
16+
17+
<encoder>
18+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %-10contextName %logger{36} - %msg%n</pattern>
19+
</encoder>
20+
</appender>
21+
22+
23+
<logger name="clojure_web_example.handler" level="DEBUG"/>
24+
<logger name="clojure_web_example.handler" level="DEBUG"/>
25+
26+
<root level="DEBUG">
27+
<appender-ref ref="CONSOLE"/>
28+
<appender-ref ref="FILE"/>
29+
</root>
30+
</configuration>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
types {
3+
text/html html htm shtml;
4+
text/css css;
5+
text/xml xml;
6+
image/gif gif;
7+
image/jpeg jpeg jpg;
8+
application/x-javascript js;
9+
application/atom+xml atom;
10+
application/rss+xml rss;
11+
12+
text/mathml mml;
13+
text/plain txt c;
14+
text/vnd.sun.j2me.app-descriptor jad;
15+
text/vnd.wap.wml wml;
16+
text/x-component htc;
17+
18+
image/png png;
19+
image/tiff tif tiff;
20+
image/vnd.wap.wbmp wbmp;
21+
image/x-icon ico;
22+
image/x-jng jng;
23+
image/x-ms-bmp bmp;
24+
image/svg+xml svg svgz;
25+
image/webp webp;
26+
27+
application/java-archive jar war ear;
28+
application/mac-binhex40 hqx;
29+
application/msword doc;
30+
application/pdf pdf;
31+
application/postscript ps eps ai;
32+
application/rtf rtf;
33+
application/vnd.ms-excel xls;
34+
application/vnd.ms-powerpoint ppt;
35+
application/vnd.wap.wmlc wmlc;
36+
application/vnd.google-earth.kml+xml kml;
37+
application/vnd.google-earth.kmz kmz;
38+
application/x-7z-compressed 7z;
39+
application/x-cocoa cco;
40+
application/x-java-archive-diff jardiff;
41+
application/x-java-jnlp-file jnlp;
42+
application/x-makeself run;
43+
application/x-perl pl pm;
44+
application/x-pilot prc pdb;
45+
application/x-rar-compressed rar;
46+
application/x-redhat-package-manager rpm;
47+
application/x-sea sea;
48+
application/x-shockwave-flash swf;
49+
application/x-stuffit sit;
50+
application/x-tcl tcl tk;
51+
application/x-x509-ca-cert der pem crt;
52+
application/x-xpinstall xpi;
53+
application/xhtml+xml xhtml;
54+
application/zip zip;
55+
56+
application/octet-stream bin exe dll;
57+
application/octet-stream deb;
58+
application/octet-stream dmg;
59+
application/octet-stream eot;
60+
application/octet-stream iso img;
61+
application/octet-stream msi msp msm;
62+
63+
audio/midi mid midi kar;
64+
audio/mpeg mp3;
65+
audio/ogg ogg;
66+
audio/x-m4a m4a;
67+
audio/x-realaudio ra;
68+
69+
video/3gpp 3gpp 3gp;
70+
video/mp4 mp4;
71+
video/mpeg mpeg mpg;
72+
video/quicktime mov;
73+
video/webm webm;
74+
video/x-flv flv;
75+
video/x-m4v m4v;
76+
video/x-mng mng;
77+
video/x-ms-asf asx asf;
78+
video/x-ms-wmv wmv;
79+
video/x-msvideo avi;
80+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
## Determines whether nginx should become a daemon and default is on.
3+
#daemon off;
4+
5+
## If master_process is off, there will be only one nginx worker running. Only use it for debug propose.
6+
## Default is on.
7+
#master_process off;
8+
9+
10+
## Defines the number of worker processes every of which will be embedded one JVM instance.
11+
## When auto is specified the number of worker processes will be the number of CPU hardware threads
12+
worker_processes 1;
13+
14+
error_log logs/error.log error;
15+
16+
events {
17+
## Defines the number of connections per worker processes.
18+
## Note that this number includes all connections (e.g. connections with proxied servers, among others),
19+
## not only connections with clients.
20+
worker_connections 1024;
21+
}
22+
23+
24+
http {
25+
26+
## include file mime.types which defines file type to mime type mappings
27+
include mime.types;
28+
29+
## Default mime type for unknown file type
30+
default_type application/octet-stream;
31+
32+
## access log, more details can be found from http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
33+
## when do performance tests try to turn off it, viz. use `access_log off;` instead.
34+
access_log logs/access.log combined;
35+
36+
sendfile on;
37+
#tcp_nopush on;
38+
39+
keepalive_timeout 65;
40+
41+
## Enable gzip, default is off
42+
#gzip on;
43+
44+
## Defines the path of JVM, when auto is used nginx-clojure will detect this by itself.
45+
jvm_path auto;
46+
47+
## Define class path. When '/*' is used after a directory path all jar files and
48+
##sub-directories will be used as the jvm classpath
49+
jvm_classpath "../target/*";
50+
51+
jvm_options "-Dnginx.clojure.logger.level=error";
52+
53+
### jvm heap memory
54+
#jvm_options "-Xms1024m";
55+
#jvm_options "-Xmx1024m";
56+
57+
## Threads number for request handler thread pool on jvm, default is 0 which means disable
58+
## thread pool mode. Check more details from section 2.4 in http://nginx-clojure.github.io/configuration.html
59+
jvm_workers 16;
60+
61+
## remote debug
62+
#jvm_options "-Xdebug";
63+
#jvm_options "-Xrunjdwp:server=y,transport=dt_socket,address=840#{pno},suspend=n";
64+
65+
server {
66+
listen 8080;
67+
server_name localhost;
68+
69+
location /api {
70+
content_handler_type java;
71+
content_handler_name nginx.clojure.jersey.spring.example.JerseySpringNginxHandler;
72+
content_handler_property jersey-context-path /api;
73+
}
74+
75+
## redirect server error pages to the static page /50x.html
76+
error_page 500 502 503 504 /50x.html;
77+
location = /50x.html {
78+
root html;
79+
}
80+
81+
}
82+
83+
84+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>nginx-clojure</groupId>
7+
<artifactId>jersey-spring-example</artifactId>
8+
<version>0.0.1</version>
9+
<packaging>jar</packaging>
10+
11+
<name>jersey-spring-example</name>
12+
13+
<properties>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<jersey.version>2.29</jersey.version>
17+
<spring.version>5.1.5.RELEASE</spring.version>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>nginx-clojure</groupId>
22+
<artifactId>nginx-jersey</artifactId>
23+
<version>0.1.6</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.glassfish.jersey.core</groupId>
27+
<artifactId>jersey-server</artifactId>
28+
<version>${jersey.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.glassfish.jersey.ext</groupId>
32+
<artifactId>jersey-spring5</artifactId>
33+
<version>${jersey.version}</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.glassfish.jersey.media</groupId>
37+
<artifactId>jersey-media-json-jackson</artifactId>
38+
<version>${jersey.version}</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework</groupId>
42+
<artifactId>spring-core</artifactId>
43+
<version>${spring.version}</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework</groupId>
47+
<artifactId>spring-context</artifactId>
48+
<version>${spring.version}</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>jakarta.servlet</groupId>
52+
<artifactId>jakarta.servlet-api</artifactId>
53+
<version>4.0.3</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>junit</groupId>
57+
<artifactId>junit</artifactId>
58+
<version>4.11</version>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>nginx-clojure</groupId>
63+
<artifactId>nginx-clojure-embed</artifactId>
64+
<version>0.5.1</version>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.github.jnr</groupId>
69+
<artifactId>jnr-posix</artifactId>
70+
<version>3.0.51</version>
71+
<scope>test</scope>
72+
</dependency>
73+
</dependencies>
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<artifactId>maven-assembly-plugin</artifactId>
78+
<version>3.0.0</version>
79+
<configuration>
80+
<descriptorRefs>
81+
<descriptorRef>jar-with-dependencies</descriptorRef>
82+
</descriptorRefs>
83+
</configuration>
84+
<executions>
85+
<execution>
86+
<id>make-assembly</id> <!-- this is used for inheritance merges -->
87+
<phase>package</phase> <!-- bind to the packaging phase -->
88+
<goals>
89+
<goal>single</goal>
90+
</goals>
91+
</execution>
92+
</executions>
93+
</plugin>
94+
</plugins>
95+
</build>
96+
<repositories>
97+
<repository>
98+
<id>central</id>
99+
<url>https://repo1.maven.org/maven2/</url>
100+
<snapshots>
101+
<enabled>false</enabled>
102+
</snapshots>
103+
<releases>
104+
<enabled>true</enabled>
105+
</releases>
106+
</repository>
107+
<repository>
108+
<id>clojars</id>
109+
<url>https://repo.clojars.org/</url>
110+
<snapshots>
111+
<enabled>true</enabled>
112+
</snapshots>
113+
<releases>
114+
<enabled>true</enabled>
115+
</releases>
116+
</repository>
117+
</repositories>
118+
</project>

0 commit comments

Comments
 (0)