Skip to content

Instantly share code, notes, and snippets.

@imechemi
Created November 5, 2019 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imechemi/435e840a3ea4e8ad3fe9cd42567126d4 to your computer and use it in GitHub Desktop.
Save imechemi/435e840a3ea4e8ad3fe9cd42567126d4 to your computer and use it in GitHub Desktop.
How to use Standalone MongoTemplate in Main class
@SpringBootApplication
public class Application implements CommandLineRunner {
@Autowired
private DeviceRepository deviceRepository;
public static void main(String[] args) {
SpringApplication.run(Application.class);
// MongoOperations mongoOps = new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(), "test"));
// RepositoryFactorySupport repositoryFactorySupport = new MongoRepositoryFactory(mongoOps);
// DeviceRepository repo = repositoryFactorySupport.getRepository(DeviceRepository.class);
}
@Override
public void run(String... args) throws Exception {
List<Device> devices = deviceRepository.findAllByOrg("JJ");
for (Device device: devices) {
System.out.println("P: " + device);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment