I have Spring Boot application:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication()
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
build.gradle contains:
testCompile group: "de.flapdoodle.embed", name: "de.flapdoodle.embed.mongo", version: "2.0.0"
and
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
There's controller which uses MongoTemplate
@RestController
@RequestMapping(Constants.MAILBOX_BASE_PATH)
public class MController {
private static final Logger log = LoggerFactory.getLogger(MailboxController.class);
private MongoTemplate mongoTemplate;
@Autowired
public MController(MongoTemplate mongoTemplate) {
this.mongoTemplate = mongoTemplate;
}
}
And test
@RunWith(SpringRunner.class)
@SpringBootTest()
@AutoConfigureMockMvc
public class MontrollerTests {
@Autowired
private MockMvc mvc;
private MongoTemplate _mongoTemplate;
...
}
My intention is to use embedded MongoDB for the above test. When i run it the following error is popped:
2017-03-05 17:14:51.993 ERROR 27857 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mController' defined...
and at the of the stacktrace there's
java.lang.IllegalStateException: Invalid mongo configuration, either uri or host/port/credentials must be specified
My application properties:
server.port=8090
spring.data.mongodb.uri=mongodb://localhost:27017/test
spring.data.mongodb.port=27017
How to solve this issue? Thanks in advance.
@EmbeddedMongoAutoConfiguration
annotation explicity in your test class. – s7vr