diff --git a/http-service/pom.xml b/http-service/pom.xml
index 62edc0538b..6b650c3205 100644
--- a/http-service/pom.xml
+++ b/http-service/pom.xml
@@ -125,7 +125,8 @@
org.mongodb
mongodb-driver-sync
- 3.10.1
+ 3.10.2
+ provided
diff --git a/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java b/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java
index 376ef11ec7..5410fc5433 100644
--- a/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java
+++ b/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java
@@ -32,6 +32,7 @@ import java.io.IOException;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
+import javax.naming.NamingException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@@ -55,6 +56,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
+import org.springframework.jndi.JndiTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.sql2o.Sql2o;
import org.sql2o.converters.Converter;
@@ -160,9 +162,21 @@ public class SpringBootWebApplication extends SpringBootServletInitializer
}
@Bean
- public MongoClient mongoClient(@Value("${mongo.host}") String host)
+ public MongoClient mongoClient(@Value("${mongo.host:}") String host, @Value("${mongo.jndiName:}") String jndiName) throws NamingException
{
- return MongoClients.create(host);
+ if (!Strings.isNullOrEmpty(jndiName))
+ {
+ JndiTemplate jndiTemplate = new JndiTemplate();
+ return jndiTemplate.lookup(jndiName, MongoClient.class);
+ }
+ else if (!Strings.isNullOrEmpty(host))
+ {
+ return MongoClients.create(host);
+ }
+ else
+ {
+ throw new RuntimeException("Either mongo.host or mongo.jndiName must be set");
+ }
}
private static DataSource getDataSource(DataSourceProperties dataSourceProperties)
diff --git a/http-service/src/main/resources/application-dev.yaml b/http-service/src/main/resources/application-dev.yaml
index cc2286e9b3..9397951858 100644
--- a/http-service/src/main/resources/application-dev.yaml
+++ b/http-service/src/main/resources/application-dev.yaml
@@ -26,6 +26,11 @@ datasource:
username: runelite
password: runelite
+# Development mongo
+mongo:
+ jndiName:
+ host: mongodb://localhost:27017
+
# Development oauth callback (without proxy)
oauth:
callback: http://localhost:8080/account/callback
diff --git a/http-service/src/main/resources/application.yaml b/http-service/src/main/resources/application.yaml
index 9905e61695..3c6fc451fe 100644
--- a/http-service/src/main/resources/application.yaml
+++ b/http-service/src/main/resources/application.yaml
@@ -31,7 +31,7 @@ redis:
host: http://localhost:6379
mongo:
- host: mongodb://localhost:27017
+ jndiName: java:comp/env/mongodb/runelite
# Twitter client for feed
runelite:
diff --git a/http-service/src/test/resources/application-test.yaml b/http-service/src/test/resources/application-test.yaml
index 0532963ade..3a8e416a54 100644
--- a/http-service/src/test/resources/application-test.yaml
+++ b/http-service/src/test/resources/application-test.yaml
@@ -15,3 +15,7 @@ datasource:
driverClassName: org.h2.Driver
type: org.h2.jdbcx.JdbcDataSource
url: jdbc:h2:mem:xptracker
+
+mongo:
+ jndiName:
+ host: mongodb://localhost:27017
\ No newline at end of file