2
I started to develop an application using the concept of microservices and I still have a lot of doubts. I have repositories and their respective entities, requests submissions work correctly but when I finish the application and start again I lose the data.
For example, I send one post
that saves the data in the bank, I give get
and get correctly however if I restart the application my get
does not return nothingness.
Why does this happen? How do I get all the data?
Repository
@RepositoryRestResource(collectionResourceRel = "veiculos", path = "veiculos")
public interface VeiculoRepository extends MongoRepository<Veiculo, String> {
Veiculo save(Veiculo veiculo);
List<Veiculo> findAll();
}
Application properties
spring.application.name=VeiculoService
spring.data.mongodb.uri=mongodb://localhost:27017/db
spring.data.rest.baseUri=/api
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.http.gzip.enabled=true
management.context-path=/actuator
info.app.name=Db Admin
info.app.description=DB
info.app.version=${project.version}
server.port=${port:8181}
server.servletPath=/
Is using the
spring-boot-starter-data-mongodb
is? Would you be able to update with yourapplication.properties
, if using? Something else, has some custom configuration?– Bruno César
Wow, I just noticed there’s a configuration of Fongo, mongoDB in memory.
– Daniela Morais
Exactly, by default it is always in memory, when you do not configure your server, there is in the boot something Embedded for everything =D See if you can configure, if not, update with your questions :)
– Bruno César
Taking advantage, there is use of Spring REST and any post, get, delete etc fall into these repositories. Is it possible to switch to the API and then call the repository? Or is this not the purpose?
– Daniela Morais
This is why you’re wearing
spring-data-rest
, then HTTP resources are published for each repository. To use as you said, use normal repository (@Repository
) and controllers in the same way as in Spring MVC (@Controller
or@RestController
)– Bruno César
Perfect, thank you! If you can publish in the form of a reply
– Daniela Morais
Okay, then I’ll respond including references =)
– Bruno César