Created
November 5, 2019 03:56
-
-
Save imechemi/435e840a3ea4e8ad3fe9cd42567126d4 to your computer and use it in GitHub Desktop.
How to use Standalone MongoTemplate in Main class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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