Spring MongoDB: Server instantly closing connection after starting - java

This is my first time using MongoDB with Spring, and all I'm trying to do is start the Spring server however the connection closes straight away after it's opened.
After looking around on similar scenarios, there were suggestions about removing the Spring Data JPA dependency which I did but did not help. Another suggestion said to add h2 as a dependency to as Spring Starter needed it before a few things, which did help as previous the connection didn't even open. I've also edited the properties file, but nothing seems to work.
Gradle file:
group = 'com.danielturato'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
runtimeOnly 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
application.properties:
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=mongo
server.port=8095
The logs:
2019-08-22 00:04:13.109 INFO 16376 --- [ main] com.danielturato.esports.Application : Starting Application on DESKTOP-E2MJ251 with PID 16376 (started by danie in D:\Projects\eSports Project)
2019-08-22 00:04:13.111 INFO 16376 --- [ main] com.danielturato.esports.Application : No active profile set, falling back to default profiles: default
2019-08-22 00:04:13.368 INFO 16376 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-22 00:04:13.411 INFO 16376 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 39ms. Found 1 repository interfaces.
2019-08-22 00:04:14.117 INFO 16376 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-08-22 00:04:14.117 INFO 16376 --- [ main] org.mongodb.driver.cluster : Adding discovered server localhost:27017 to client view of cluster
2019-08-22 00:04:14.150 INFO 16376 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:14}] to localhost:27017
2019-08-22 00:04:14.153 INFO 16376 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 0]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1950400}
2019-08-22 00:04:14.154 INFO 16376 --- [localhost:27017] org.mongodb.driver.cluster : Discovered cluster type of STANDALONE
2019-08-22 00:04:14.378 INFO 16376 --- [ main] com.danielturato.esports.Application : Started Application in 1.482 seconds (JVM running for 1.99)
2019-08-22 00:04:14.414 INFO 16376 --- [ main] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:15}] to localhost:27017
2019-08-22 00:04:14.429 INFO 16376 --- [ Thread-2] org.mongodb.driver.connection : Closed connection [connectionId{localValue:2, serverValue:15}] to localhost:27017 because the pool has been closed.
If anyone has anymore suggestions, that would be appreciated !

Related

Spring boot Graphql Not worked

the application stands up but the graphql end point is not produced. I generated this project on start.spring.io but originally settings is the graphql end point not produced
application.yml
datasource:
url: jdbc:postgresql://localhost:10000/postgres
username: admin
password: 12345
graphql:
graphiql:
enabled: true
log
2022-07-07 09:44:40.006 INFO 10960 --- [ restartedMain] c.i.e.EmployeeManagmentApplication : No active profile set, falling back to 1 default profile: "default"
2022-07-07 09:44:40.173 INFO 10960 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-07-07 09:44:40.173 INFO 10960 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-07-07 09:44:41.787 INFO 10960 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2022-07-07 09:44:41.788 INFO 10960 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-07-07 09:44:41.823 INFO 10960 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 13 ms. Found 0 JPA repository interfaces.
2022-07-07 09:44:41.866 INFO 10960 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2022-07-07 09:44:41.869 INFO 10960 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2022-07-07 09:44:41.891 INFO 10960 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 2 ms. Found 0 Redis repository interfaces.
2022-07-07 09:44:43.152 INFO 10960 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-07-07 09:44:43.168 INFO 10960 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-07-07 09:44:43.168 INFO 10960 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.64]
2022-07-07 09:44:43.326 INFO 10960 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-07-07 09:44:43.326 INFO 10960 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3149 ms
2022-07-07 09:44:43.500 INFO 10960 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-07-07 09:44:43.722 INFO 10960 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-07-07 09:44:43.794 INFO 10960 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-07-07 09:44:43.927 INFO 10960 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.9.Final
2022-07-07 09:44:44.284 INFO 10960 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-07-07 09:44:44.547 INFO 10960 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2022-07-07 09:44:44.780 INFO 10960 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-07-07 09:44:44.793 INFO 10960 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-07-07 09:44:44.903 WARN 10960 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-07-07 09:44:46.688 INFO 10960 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-07-07 09:44:46.779 INFO 10960 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-07-07 09:44:46.805 INFO 10960 --- [ restartedMain] c.i.e.EmployeeManagmentApplication : Started EmployeeManagmentApplication in 7.652 seconds (JVM running for 10.128)```
pom.xml

Localhost:8080, showing 404 Error in Spring Boot Application

I am having some issues in regards to my spring boot microservice, I have been able to successfully connect my microservice to my SQL instance running on Google Cloud, but for some reason when I try to test if the controllers are working using a sample endpoint which simply returns a String "Working" I get a 404 not found error, I have also tried a sample blank project, with no dependency except the ones needed to get Spring Boot up and running, however I still face the same problem, that is I get a 404 Not Found error, even though it is properly compiling and running. I have checked my firewall and it has not blocked the service.
Here is the Controller
VideoController.java
package com.example.demo.Controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class VideoController {
#RequestMapping(path = "/test")
public String index() {
return "Greetings from Spring Boot!";
}
}
Run Logs
2021-07-11 16:53:28.677 INFO 16456 --- [ main] com.example.demo.Run.DemoApplication : Starting DemoApplication using Java 15.0.2 on DESKTOP-OO1339O with PID 16456 (C:\Users\Engineering\IdeaProjects\gcp-demo\build\classes\java\main started by Engineering in C:\Users\Engineering\IdeaProjects\gcp-demo)
2021-07-11 16:53:28.679 INFO 16456 --- [ main] com.example.demo.Run.DemoApplication : No active profile set, falling back to default profiles: default
2021-07-11 16:53:29.149 INFO 16456 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-07-11 16:53:29.161 INFO 16456 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 5 ms. Found 0 JPA repository interfaces.
2021-07-11 16:53:29.510 INFO 16456 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-07-11 16:53:29.517 INFO 16456 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-07-11 16:53:29.517 INFO 16456 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.48]
2021-07-11 16:53:29.624 INFO 16456 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-07-11 16:53:29.625 INFO 16456 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 913 ms
2021-07-11 16:53:29.751 INFO 16456 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-07-11 16:53:29.788 INFO 16456 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
2021-07-11 16:53:29.888 INFO 16456 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-07-11 16:53:29.971 INFO 16456 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-07-11 16:53:30.025 INFO 16456 --- [ main] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:30.025 INFO 16456 --- [ main] c.g.cloud.sql.core.CoreSocketFactory : First Cloud SQL connection, generating RSA key pair.
2021-07-11 16:53:31.820 INFO 16456 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-07-11 16:53:31.835 INFO 16456 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
2021-07-11 16:53:31.924 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:32.035 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:32.040 INFO 16456 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-07-11 16:53:32.049 INFO 16456 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-07-11 16:53:32.099 WARN 16456 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-07-11 16:53:32.147 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:32.245 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:32.265 INFO 16456 --- [ main] c.g.c.s.core.DefaultCredentialsProvider : Default credentials provider for service account acn-demo-app#involuted-earth-319307.iam.gserviceaccount.com
2021-07-11 16:53:32.265 INFO 16456 --- [ main] c.g.c.s.core.DefaultCredentialsProvider : Scopes in use by default credentials: [https://www.googleapis.com/auth/pubsub, https://www.googleapis.com/auth/spanner.admin, https://www.googleapis.com/auth/spanner.data, https://www.googleapis.com/auth/datastore, https://www.googleapis.com/auth/sqlservice.admin, https://www.googleapis.com/auth/devstorage.read_only, https://www.googleapis.com/auth/devstorage.read_write, https://www.googleapis.com/auth/cloudruntimeconfig, https://www.googleapis.com/auth/trace.append, https://www.googleapis.com/auth/cloud-platform, https://www.googleapis.com/auth/cloud-vision, https://www.googleapis.com/auth/bigquery, https://www.googleapis.com/auth/monitoring.write]
2021-07-11 16:53:32.277 INFO 16456 --- [ main] c.g.c.s.a.c.GcpContextAutoConfiguration : The default project ID is XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST
2021-07-11 16:53:32.353 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:32.378 INFO 16456 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-07-11 16:53:32.389 INFO 16456 --- [ main] com.example.demo.Run.DemoApplication : Started DemoApplication in 4.027 seconds (JVM running for 4.567)
2021-07-11 16:53:32.449 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:32.554 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:32.659 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [involuted-earth-319307:australia-southeast1:cloud-demo] via SSL socket.
2021-07-11 16:53:32.768 INFO 16456 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXXXHIDDENFROMSTACKOVERFLOWPOST] via SSL socket.
2021-07-11 16:53:38.167 INFO 16456 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-07-11 16:53:38.167 INFO 16456 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-07-11 16:53:38.168 INFO 16456 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
My Application Properties File
Application.properties
spring.main.allow-bean-definition-overriding=true
spring.datasource.url=SOMEVALUE HERE
spring.datasource.username=SOMEVALUE HERE
spring.datasource.password=SOMEVALUEHERE
spring.cloud.gcp.sql.database-name=SOMEVALUEHERE
spring.cloud.gcp.sql.instance-connection-name=SOMVEVALUEHERE
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
My File Structure
My Application Run Class
DemoApplication.Java
package com.example.demo.Run;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
DemoApplication is in the com.example.demo.Run package. This means that its component scanning, enabled via #SpringBootApplication, will find components in com.example.demo.Run and in any sub-packages such as com.example.demo.Run.example. The rest of your code, therefore, isn’t in a package where it’ll be found.
I would fix this by moving DemoApplication up into the com.example.demo package. This will mean that components in any of your existing com.example.demo.* packages is found.
Alternatively, you could leave DemoApplication where it is and use the scanBasePackages attribute on #SpringBootApplication to list all your other com.example.demo.* packages. This will be more verbose than moving DemoApplication and would require changes every time you introduce a new package.
As you said your first problem was because of the package level of your main class and Controller class. But the second problem does not seem to depend on refactoring the main class. It's related to conflict of the version of your JDK or another library

Java Spring error with #Service #Controller #Repository: Error creating bean

please, I need some help, I've been stuck with this error 2 days.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adsController': Unsatisfied dependency expressed through field 'shortUrlService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shortUrlServiceImpl': Unsatisfied dependency expressed through field 'shortUrlRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shortUrlRepository' defined in com.codepressed.urlShortener.dao.ShortUrlRepository defined in #EnableMongoRepositories declared on MongoRepositoriesRegistrar.EnableMongoRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property desc found for type LocalDateTime! Traversed path: ShortUrl.creationDate.
Error display
This is my code:
Service class
#Service
public class AdvertisementServiceImpl implements AdvertisementService{
#Autowired
AdvertisementRepository advertisementRepository;
#Autowired
private MongoUtilsService mongoUtilsService;
#Override
public Advertisement save(Advertisement advertisement) {
advertisement.set_id(mongoUtilsService.getNextValue("AD"));
return advertisementRepository.insert(advertisement);
}
#Override
public void removeAd(Advertisement advertisement) {
advertisementRepository.delete(advertisement);
}
#Override
public Advertisement randomAd() {
List<Advertisement> allAds = advertisementRepository.findAll();
Random random = new Random();
return allAds.get(random.nextInt(allAds.size()-1));
}
}
My repository
#RepositoryRestResource
public interface AdvertisementRepository extends MongoRepository<Advertisement,Long> {
}
Controller class
#Controller
#RequestMapping("/ad")
public class AdsController {
#Autowired
AdvertisementService advertisementService;
#Autowired
ShortUrlService shortUrlService;
#GetMapping(value="/{id}")
public String getRandomAd(#PathVariable Long id, Model model){
model.addAttribute("ad", advertisementService.randomAd());
String url;
if (shortUrlService.findUrlById(id) != null){
url = shortUrlService.findUrlById(id);
}else if (shortUrlService.findUrlByCustom(String.valueOf(id)) != null){
url = shortUrlService.findUrlByCustom(String.valueOf(id));
}else {
url = "/error404.html";
}
model.addAttribute("url", url);
return "go";
}
I would like to use the ServiceImpl and Service but I don't know why wouldn't I be able to autowire them.
Additionaly, I have on my Config Class the following annotation:
#ComponentScan({"com.codepressed.urlShortener", "com.codepressed.urlShortener.dao",
"com.codepressed.urlShortener.service", "com.codepressed.urlShortener.controller"})
but doesn't seem to be enough...
please, any help is appreciated, I can't see the error or I don't understand it.
GITHUB REPO: https://github.com/codepressed/Jurly/tree/master/src/main/java/com/codepressed/urlShortener
I just cloned your code, on github.
I found that your method naming does not conform to the Spring-Data JPA specification.
Rename ShortUrlRepository method:
List<ShortUrl> findFirst10ByCreationDateDesc();
to:
List<ShortUrl> findFirst10ByOrderByCreationDateDesc();
When this problem is solved, run the application,console output:
No session repository could be auto-configured, check your configuration
So I created a mongo http session config:
package com.codepressed.urlShortener.config;
import org.springframework.context.annotation.Bean;
import org.springframework.session.data.mongo.JdkMongoSessionConverter;
import org.springframework.session.data.mongo.config.annotation.web.http.EnableMongoHttpSession;
import java.time.Duration;
#EnableMongoHttpSession
public class HttpSessionConfig {
#Bean
public JdkMongoSessionConverter jdkMongoSessionConverter() {
return new JdkMongoSessionConverter(Duration.ofMinutes(30));
}
}
Then I run the application again,No exception output!
2021-06-18 00:06:49.844 INFO 13960 --- [ main] c.c.u.UrlShortenerApplication : Starting UrlShortenerApplication using Java 11.0.10 on Mashiros-iMac.lan with PID 13960 (/Users/rat/IdeaProjects/Jurly/target/classes started by rat in /Users/rat/IdeaProjects/Jurly)
2021-06-18 00:06:49.850 INFO 13960 --- [ main] c.c.u.UrlShortenerApplication : No active profile set, falling back to default profiles: default
2021-06-18 00:06:50.295 INFO 13960 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2021-06-18 00:06:50.329 INFO 13960 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 32 ms. Found 2 MongoDB repository interfaces.
2021-06-18 00:06:50.667 INFO 13960 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-06-18 00:06:50.674 INFO 13960 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-06-18 00:06:50.674 INFO 13960 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-06-18 00:06:50.717 INFO 13960 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-06-18 00:06:50.718 INFO 13960 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 833 ms
2021-06-18 00:06:50.838 INFO 13960 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-06-18 00:06:50.875 INFO 13960 --- [127.0.0.1:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:1}] to 127.0.0.1:27017
2021-06-18 00:06:50.875 INFO 13960 --- [127.0.0.1:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:2}] to 127.0.0.1:27017
2021-06-18 00:06:50.876 INFO 13960 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=127.0.0.1:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=9, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=11069828}
2021-06-18 00:06:51.052 INFO 13960 --- [ main] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:3}] to 127.0.0.1:27017
2021-06-18 00:06:51.067 INFO 13960 --- [ main] o.s.s.d.m.AbstractMongoSessionConverter : Creating TTL index on field expireAt
2021-06-18 00:06:51.536 INFO 13960 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-06-18 00:06:51.600 INFO 13960 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2021-06-18 00:06:51.891 INFO 13960 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 1c0d09bd-73cc-42aa-8f6a-df157db252fe
2021-06-18 00:06:52.022 INFO 13960 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#1e95f584, org.springframework.security.web.context.SecurityContextPersistenceFilter#1a336906, org.springframework.security.web.header.HeaderWriterFilter#39afe59f, org.springframework.security.web.csrf.CsrfFilter#3a3316b6, org.springframework.security.web.authentication.logout.LogoutFilter#57fce8b, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#1b4ba615, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#3a9c11fb, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#54997f67, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#18e8eb59, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#20f63ddc, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#24f177f5, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#bf4e48e, org.springframework.security.web.session.SessionManagementFilter#43756cb, org.springframework.security.web.access.ExceptionTranslationFilter#48ee3c2d, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#e6e5da4]
2021-06-18 00:06:52.105 INFO 13960 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-06-18 00:06:52.115 INFO 13960 --- [ main] c.c.u.UrlShortenerApplication : Started UrlShortenerApplication in 2.542 seconds (JVM running for 3.116)
I think you should refer to the following tutorials:
Spring Session with MongoDB
Sorting Query Results with Spring Data

#SpringBootApplication Annotation not finding beans in classpath

From my understanding using #SpringBootApplication is the equivalent of having #EnableAutoConfiguration and #ComponentScan. For this reason I can't understand why Spring isn't finding my annotations. As far as I'm aware the project structure is as it should be and everything is annotated properly. However when I visit the mapped endpoint http://localhost:8080/dashboard or http://localhost:8080/dashboard/, I see a 404 error.
I just created a new Spring Boot project using IntelliJ's built in Spring Initialiser, I selected Spring Web, and a few components for Postgres. Inside the project I can't find any additional .xml files for configuration. However, I did find:
DataSourceInitializerInvoker.java - which hasn't been edited
ConfigurationPropertiesAutoConfiguration.java - which hasn't been edited
Structure of my project is as follows:
com
+-abcde
+-appname
+-controllers
DashboardController.java
Application.java
Application.java:
package com.abcde.appname;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
DashboardController.java
package com.abcde.appname.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
#RequestMapping("/dashboard")
public class DashboardController {
#Autowired
public DashboardController() {
}
#GetMapping
public ModelAndView renderDashboard() {
return new ModelAndView("dashboard/index");
}
}
Alongside these files I also have the following,
application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=user
spring.datasource.driver-class-name=org.postgresql.Driver
spring.main.banner-mode=off
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.abcde'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '14'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
runtimeOnly 'org.postgresql:postgresql'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
stacktrace
2020-09-09 23:24:46.053 INFO 57966 --- [ main] c.d.f.Application : Starting Application on OP-MacBook-Pro.local with PID 57966 (/Users/op/IdeaProjects/lalala/build/classes/java/main started by op in /Users/op/IdeaProjects/lalala)
2020-09-09 23:24:46.054 INFO 57966 --- [ main] c.d.f.Application : No active profile set, falling back to default profiles: default
2020-09-09 23:24:46.374 INFO 57966 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-09-09 23:24:46.388 INFO 57966 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 10ms. Found 0 JPA repository interfaces.
2020-09-09 23:24:46.716 INFO 57966 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-09-09 23:24:46.720 INFO 57966 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-09-09 23:24:46.720 INFO 57966 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-09-09 23:24:46.775 INFO 57966 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-09-09 23:24:46.775 INFO 57966 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 700 ms
2020-09-09 23:24:46.832 INFO 57966 --- [ main] o.f.c.internal.license.VersionPrinter : Flyway Community Edition 6.4.4 by Redgate
2020-09-09 23:24:46.835 INFO 57966 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-09-09 23:24:46.872 INFO 57966 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-09-09 23:24:46.879 INFO 57966 --- [ main] o.f.c.internal.database.DatabaseFactory : Database: jdbc:postgresql://localhost:5432/postgres (PostgreSQL 12.3)
2020-09-09 23:24:46.901 INFO 57966 --- [ main] o.f.core.internal.command.DbValidate : Successfully validated 1 migration (execution time 00:00.011s)
2020-09-09 23:24:46.905 INFO 57966 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema "public": 10
2020-09-09 23:24:46.905 INFO 57966 --- [ main] o.f.core.internal.command.DbMigrate : Schema "public" is up to date. No migration necessary.
2020-09-09 23:24:46.960 INFO 57966 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-09 23:24:46.985 INFO 57966 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-09-09 23:24:47.000 WARN 57966 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-09-09 23:24:47.010 INFO 57966 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.20.Final
2020-09-09 23:24:47.070 INFO 57966 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-09-09 23:24:47.122 INFO 57966 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-09-09 23:24:47.253 INFO 57966 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-09-09 23:24:47.257 INFO 57966 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-09-09 23:24:47.264 INFO 57966 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-09-09 23:24:47.265 INFO 57966 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-09-09 23:24:47.266 INFO 57966 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-09-09 23:24:47.273 INFO 57966 --- [ main] c.d.f.lalala : Started Application in 1.401 seconds (JVM running for 1.885)
2020-09-09 23:24:49.520 INFO 57966 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-09-09 23:24:49.520 INFO 57966 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-09-09 23:24:49.524 INFO 57966 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 4 ms
Any insight into this problem would be much appreciated. Many thanks
It's probably successfully invoking the renderDashboard() and is not finding "dashboard/index". You can verify that by debugging and setting a breakpoint or adding a log/System.out println statement. Does your index file exist and is it setup correctly?

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure when trying to build spring boot docker image

I am trying to build my docker image for my spring boot application but keep encountering this error:
:: Spring Boot :: (v2.2.5.RELEASE)
2020-05-31 02:18:39.820 INFO 63 --- [ main] c.g.Apollo.ApolloApplicationTests : Starting ApolloApplicationTests on 4b284b60945e with PID 63 (started by root in /build)
2020-05-31 02:18:39.838 INFO 63 --- [ main] c.g.Apollo.ApolloApplicationTests : No active profile set, falling back to default profiles: default
2020-05-31 02:18:42.208 INFO 63 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-05-31 02:18:42.467 INFO 63 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 216ms. Found 3 JPA repository interfaces.
2020-05-31 02:18:44.902 INFO 63 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-31 02:18:46.575 ERROR 63 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:354) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:554) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.2.jar:na]
Terminal when successfully running in intellij:
:: Spring Boot :: (v2.2.5.RELEASE)
2020-05-31 01:04:39.322 INFO 19524 --- [ restartedMain] c.g.Apollo.ApolloApplication : Starting ApolloApplication on asd-PC with PID 19524 (C:\Projects\Apollo\target\classes started by asd in C:\Projects\Apollo)
2020-05-31 01:04:39.324 INFO 19524 --- [ restartedMain] c.g.Apollo.ApolloApplication : No active profile set, falling back to default profiles: default
2020-05-31 01:04:39.354 INFO 19524 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in C:\Users\asd\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.2\jaxb-runtime-2.3.2.jar referenced one or more files that do not exist: file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.xml.bind-api-2.3.2.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/txw2-2.3.2.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/istack-commons-runtime-3.0.8.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/stax-ex-1.8.1.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/FastInfoset-1.2.16.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.activation-api-1.2.1.jar
2020-05-31 01:04:39.354 INFO 19524 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-05-31 01:04:39.354 INFO 19524 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-05-31 01:04:39.785 INFO 19524 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-05-31 01:04:39.846 INFO 19524 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 54ms. Found 3 JPA repository interfaces.
2020-05-31 01:04:40.214 INFO 19524 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-31 01:04:40.220 INFO 19524 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-31 01:04:40.221 INFO 19524 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-05-31 01:04:40.293 INFO 19524 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-31 01:04:40.293 INFO 19524 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 939 ms
2020-05-31 01:04:40.365 INFO 19524 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-31 01:04:40.702 INFO 19524 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-05-31 01:04:40.731 INFO 19524 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-05-31 01:04:40.800 INFO 19524 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-05-31 01:04:40.919 INFO 19524 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-05-31 01:04:41.006 INFO 19524 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2020-05-31 01:04:41.407 INFO 19524 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-05-31 01:04:41.413 INFO 19524 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-05-31 01:04:41.650 WARN 19524 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-05-31 01:04:41.717 INFO 19524 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-31 01:04:41.967 INFO 19524 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-05-31 01:04:41.995 INFO 19524 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-31 01:04:41.997 INFO 19524 --- [ restartedMain] c.g.Apollo.ApolloApplication : Started ApolloApplication in 2.911 seconds (JVM running for 3.899)
My Dockerfile:
FROM maven:3.6.3-jdk-11-slim AS MAVEN_BUILD
COPY pom.xml /build/
COPY src /build/src/
WORKDIR /build/
RUN mvn package
FROM openjdk:11-jre-alpine
WORKDIR /app
COPY --from=MAVEN_BUILD /build/target/*.war /app/app.war
ENTRYPOINT ["java", "-jar", "app.war"]
My application.properties:
## GraphQL SPQR ##
server.port=8080
graphql.spqr.gui.enabled=true
graphql.spqr.http.endpoint=/graphql
graphql.spqr.ws.endpoint=/graphql
## Database Properties ##
spring.datasource.url=jdbc:mysql://localhost:3306/innodb
spring.datasource.username=root
spring.datasource.password=1234
My application works when I build and run the project in Intellij but not when I try and build my docker image. I am using MySQL and have just been connecting on localhost on port 3306.
The error message seems to indicate the issue is failing to connect to the database. From your settings, it appears that you are trying to connect to the DB using localhost:3306. That will not work when you are running the application in a container because docker creates its own network which is separate from you machine’s network. So, localhost in the container does not refer to your machine.
You need to instead setup a docker network that will allow your container to access the database in a specific IP address.
Here is an article with the specifics:
https://nickjanetakis.com/blog/docker-tip-35-connect-to-a-database-running-on-your-docker-host
Note that I have assumed from your post, that the DB is installed in your host machine. If it is not and the DB is running in its own container, the you need to create a docker network and attach both containers to that network.
I had the same issue and resolved it by changing localhost to the service name on which MySQL was running.
Below is my docker-compose and application.properties files
docker-compose.yml
version: '3.8'
services:
app:
container_name: tvms
build:
context: .
dockerfile: Dockerfile
tty: true
volumes:
- ../..:/workspaces:cached
ports:
- 8990:8990
networks:
- impaq
links:
- db:db
db:
image: percona:8.0
privileged: true
restart: always
container_name: standalone-mysql
environment:
MYSQL_ROOT_PASSWORD: ****
volumes:
- perconadata:/var/lib/mysql
ports:
- 3306:3306
networks:
- impaq
networks:
impaq:
volumes:
perconadata:
application.propeties
#datasource
spring.datasource.url=jdbc:mysql://db:3306/db_name
spring.datasource.username=root
spring.datasource.password=*****
For me below solution worked
change your datasource url from
This:
spring.datasource.url=jdbc:mysql://localhost:3306/innodb
To:
spring.datasource.url=jdbc:mysql://localhost:3306/innodb?useSSL=false

Categories

Resources