Spring Data, MongoDB, and Spring Boot
You really can quickly develop a microservice to access MongoDB from Java 8 with little coding. Give it a try... easy like Sunday morning.
Join the DZone community and get the full member experience.
Join For FreeIt’s so simple, I almost don’t believe it. And, if this seems to hard, try using JHipster.
You really can quickly develop a microservice to access MongoDB from Java 8 with little coding. Give it a try. Java 8 + Spring Boot + Gradle + MongoDB + YAML. Easy like Sunday morning.
Gradle
compile(“org.springframework.boot:spring-boot-starter-data-mongodb”)
Application.yml
spring.profiles.default: local
Application-local.yml
spring.data.mongodb.database: my-db-engine
spring.data.mongodb.uri: mongodb://localhost:2701
Repository
import org.springframework.data.repository.CrudRepository;
import com.mysite.service.stuff.model.MongoModel;
public interface IMongoModelEnabledRepository extends CrudRepository<MongoModel, String>
{
public MongoModel findByDomain(String domain);
}
Usage
@Autowired
IMongoModelEnabledRepository myrepo;
myrepo.findByDomain(domain);
Spring Boot Application
@PropertySource(“classpath:application.yml”)
@EnableAsync
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Spring Framework
Spring Boot
MongoDB
Data (computing)
Published at DZone with permission of Tim Spann, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Observability Architecture: Financial Payments Introduction
-
Understanding the Role of ERP Systems in Modern Software Development
-
DevOps in Legacy Systems
-
Never Use Credentials in a CI/CD Pipeline Again
Comments