Skip to content

Instantly share code, notes, and snippets.

@lordofthejars
Created September 23, 2014 19:10
Show Gist options
  • Select an option

  • Save lordofthejars/3180b2ccfbd765b7ac5c to your computer and use it in GitHub Desktop.

Select an option

Save lordofthejars/3180b2ccfbd765b7ac5c to your computer and use it in GitHub Desktop.
@ApplicationScoped
public class MongoDBProducer {
@Resource(name = "mongoUri")
private MongoClientURI mongoClientURI;
private DB db;
@PostConstruct
public void init() throws UnknownHostException {
MongoClient mongoClient = new MongoClient(mongoClientURI);
db = mongoClient.getDB(mongoClientURI.getDatabase());
}
@Produces
public DB createDB() {
return db;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment