Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

前端 未结 28 2559
天命终不由人
天命终不由人 2020-11-30 19:57

I am working on a Spring Boot Batch example with MongoDB and I have already started the mongod server.

When I launch my application, I

28条回答
  •  眼角桃花
    2020-11-30 20:35

    It can be that your resources directory is not added to classpath when creating a project via Spring Initializr. So your application is never loading the application.properties file that you have configured.

    To make a quick test if this is the case, add the following to your application.properties file:

    server.port=8081
    

    Now when running your application you should see in the spring boot console output something like this:

    INFO  o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): **8081** (http) with context path ''
    

    If your port is still default 8080 and not changed to 8081, your application.properties files is obviously not loading.

    You can also check if your application runs with gradle bootRun from command line. Which most likely will be work.

    Solution:

    1. Close IntelliJ, then inside your project folder delete the ".idea" folder
    2. Reimport your project to IntelliJ like following: "Import Project" -> "select ONLY your build.gradle file to import". (IntelliJ will automatically grab the rest)
    3. build and run your application again

    See official answer by IntelliJ Support: IDEA-221673

提交回复
热议问题