http-service: use jndi provided mongo
This commit is contained in:
@@ -125,7 +125,8 @@
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver-sync</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.10.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user