I am developling a Springboot Application with an active database. First, I tried configuring my database by adding the following in application.properties:
spring.datasource.url = jdbc:mysql://127.0.0.1:3306/schema_name?characterEncoding=UTF-8&serverTimezone=GMT%2B8
spring.datasource.username = root
spring.datasource.password = password
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.hdm2ddl.auto = update
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.format_sql = true
The Springboot Application can run perfectly fine with this configuration. However, as I try to move the above configuration lines in application-dev.properties and add spring.profiles.active = dev in my original application.properties, the following error yields:
2021-04-10 11:29:59.097 WARN 58148 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via
factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2021-04-10 11:29:59.103 INFO 58148 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-04-10 11:29:59.134 INFO 58148 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-10 11:29:59.172 ERROR 58148 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev are currently active).
I searched for solutions but all of them suggests to either disable/exclude JPA (not the case) or configure the database connection properly (which I did, and succeeded in the main profile); from the error message it is also shown that dev profile is active. How can I solve this problem?
Related
I have a cluster of servers (Windows & UNIX). When I'm running a jar file I'm receiving this error on some of the servers at my cluster (regardless of the OS type).
***************************
APPLICATION FAILED TO START
***************************
Description:
Field settingsDao in com.ogydocs.wave.service.ApplicationSettingsLoader required a bean named 'cacheManager' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'cacheManager' in your configuration.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I am developing a Springboot application which connects to a remote Couchbase server to fetch data. The application is working fine for the local Couchbase server in my machine. But when I configured the API properties for the remote database, it throws a java.util.concurrent.TimeoutException. Following given is my error log.
2020-08-31 08:50:50.596 WARN 12692 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fileUploadController': Unsatisfied dependency expressed through field 'predictionService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'predictionServiceImpl': Unsatisfied dependency expressed through field 'predictionDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'predictionDaoImpl': Unsatisfied dependency expressed through field 'predictionRepository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'couchbaseRepositoryOperationsMapping' defined in class path resource [com/example/couchbaseService/Configuration/CouchbaseConfiguration.class]: Unsatisfied dependency expressed through method 'repositoryOperationsMapping' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couchbaseTemplate' defined in class path resource [com/example/couchbaseService/Configuration/CouchbaseConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.couchbase.core.CouchbaseTemplate]: Factory method 'couchbaseTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couchbaseBucket' defined in class path resource [com/example/couchbaseService/Configuration/CouchbaseConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.Bucket]: Factory method 'couchbaseClient' threw exception; nested exception is java.lang.RuntimeException: java.util.concurrent.TimeoutException
2020-08-31 08:50:50.642 INFO 12692 --- [ main] c.c.client.core.env.CoreEnvironment : Shutdown kvIoPool: success
2020-08-31 08:50:50.645 INFO 12692 --- [ main] c.c.client.core.env.CoreEnvironment : Shutdown viewIoPool: success
2020-08-31 08:50:50.652 INFO 12692 --- [ main] c.c.client.core.env.CoreEnvironment : Shutdown queryIoPool: success
2020-08-31 08:50:50.656 INFO 12692 --- [ main] c.c.client.core.env.CoreEnvironment : Shutdown searchIoPool: success
2020-08-31 08:50:50.659 INFO 12692 --- [ main] c.c.client.core.env.CoreEnvironment : Shutdown Core Scheduler: success
2020-08-31 08:50:50.659 INFO 12692 --- [ Thread-5] c.c.client.core.env.CoreEnvironment : Shutdown Netty: success
2020-08-31 08:50:50.662 INFO 12692 --- [ main] c.c.client.core.env.CoreEnvironment : Shutdown Runtime Metrics Collector: success
2020-08-31 08:50:50.666 INFO 12692 --- [ main] c.c.client.core.env.CoreEnvironment : Shutdown Latency Metrics Collector: success
2020-08-31 08:50:50.683 INFO 12692 --- [ cb-io-1-2] c.c.client.core.endpoint.Endpoint : [][KeyValueEndpoint]: Got notified from Channel as inactive, attempting reconnect.
2020-08-31 08:50:50.690 INFO 12692 --- [entExecutor-2-2] c.c.client.core.env.CoreEnvironment : Shutdown IoPool: success
2020-08-31 08:50:50.703 INFO 12692 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
As I couldn't figure out the cause, I tested the API in different windows machines and all attempts gave the same error. But, API successfully starts in a MacOS machine and works fine. I am using Java 11 and Couchbase enterprise edition 6.5.0. My springboot version is 2.0.1. Can anyone help me on this to figure out the cause? Thank you.
If you claim that it works on a Mac, and there's no problem with the code, then the problem could be with your corporate networking policy. Often times, companies have different profiles for Windows than Macs. It could also be a firewall/antivirus blocking outgoing traffic on your PC that Mac doesn't have.
To verify this theory, run a Couchbase server locally on your PC and see if you can connect to it.
I am developing a desktop application with spring boot using the STS 4 IDE. Everything works fine inside STS, I have different properties files for different profiles and the main properties file application.properties all inside the resources folder
src/main/resources
application.properties
application-dev.properties
application-prod.properties
In the application.properties I define the environment and the packages to scan to find the entities for the two app databases:
spring.profiles.active=dev
wms.basepackage=com.wms
app.basepackage=es.app
I run the app using boot dasboard and everything is OK. The problem is when exporting the JAR and I execute it from the command using the instruction
java -jar -Dspring.profiles.active=dev RunableApp4.jar
The application fails with the error:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [es.app.InterfaceApplication]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'wms.basepackage' in value "${wms.basepackage}"
I noticed in the log Differences in steps for run the application from the command line than when run using STS:
STS STEPS (USING BOOT DASHBOARD):
es.app.InterfaceApplication Starting InterfaceApplication on matias-pc with PID 27945 (/home/matias/desarrollo/InterfaceApp/bin/main started by matias in /home/matias/desarrollo/InterfaceApp)
es.app.InterfaceApplication The following profiles are active: dev
o.s.boot.SpringApplication Loading source class es.app.InterfaceApplication
o.s.b.c.c.ConfigFileApplicationListener Activated activeProfiles dev
o.s.b.c.c.ConfigFileApplicationListener Profiles already activated, '[dev]' will not be applied
o.s.b.c.c.ConfigFileApplicationListener Loaded config file 'file:/home/matias/desarrollo/InterfaceApp/bin/main/application.properties' (classpath:/application.properties)
o.s.b.c.c.ConfigFileApplicationListener Loaded config file 'file:/home/matias/desarrollo/InterfaceApp/bin/main/application-dev.properties' (classpath:/application-dev.properties) for profile dev
m.s.d.r.c.RepositoryConfigurationDelegate Bootstrapping Spring Data JPA repositories in DEFAULT mode.
m.s.d.r.c.RepositoryConfigurationDelegate Finished Spring Data repository scanning in 60ms. Found 13 JPA repository interfaces.
m.s.d.r.c.RepositoryConfigurationDelegate Bootstrapping Spring Data JPA repositories in DEFAULT mode.
m.s.d.r.c.RepositoryConfigurationDelegate Finished Spring Data repository scanning in 8ms. Found 4 JPA repository interfaces.
The ConfigFileApplicationListener enters the scene and loads the main
application.properties file and the application-dev.properties environment file. Then the RepositoryConfigurationDelegate correctly loads the repositories
COMMAND LINE STEPS:
java -jar -Dspring.profiles.active=dev RunableApp4.jar
13:07:49.453 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'spring.profiles.active' in PropertySource 'systemProperties' with value of type String
13:07:49.455 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profiles [dev]
13:07:49.455 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profiles [dev]
3:07:49.537 [main] INFO es.app.InterfaceApplication - Starting InterfaceApplication on matias-pc with PID 32173 (/home/matias/Documentos/JARS/RunableApp4.jar started by matias in /home/matias/Documentos/JARS)
13:07:49.537 [main] DEBUG es.app.InterfaceApplication - Running with Spring Boot, Spring
13:07:49.537 [main] INFO es.app.InterfaceApplication - The following profiles are active: dev
13:07:49.538 [main] DEBUG org.springframework.boot.SpringApplication - Loading source class es.app.InterfaceApplication
13:07:49.580 [main] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#7a1ebcd8
13:07:49.584 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
13:07:49.642 [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Identified candidate component class: URL [jar:file:/home/matias/Documentos/JARS/RunableApp4.jar!/mx/gm3s/configuracion/ConfiguracionDSErp.class]
.
.
Read candidate components
13:07:49.861 [main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [es.app.InterfaceApplication]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'wms.basepackage' in value "${wms.basepackage}"
13:07:49.864 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [es.app.InterfaceApplication]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'wms.basepackage' in value "${wms.basepackage}"
The ConfigFileApplicationListener and RepositorConfigurationDelegate do not arrive at the scene, The AnnotationConfigApplicationContext starts to scan components and fails due to being unable to resolve properties values.
I already tried to send properties file as argument but the result is the same:
java -jar -Dspring.profiles.active=dev -Dspring.config.location=file:/InterfaceApp/src/main/resources/application.properties RunableApp4.jar
The main classes are:
#SpringBootApplication
#Import(ConfigInterfaceApp.class)
#EnableScheduling
public class InterfaceApp {
public static void main(String[] args) {
SpringApplication.run(InterfaceApp.class, args);
}
#Configuration
#EnableAutoConfiguration
#ComponentScan(basePackages = {"${wms.basepackage}", "${app.basepackage}"})
public class ConfigInterfaceApp {
}
What am I doing wrong?
Read application.properties in your application as follows:
ClassLoader.class.getResourceAsStream("/path/to/application.properties");
Alternatively,
ClassLoader.getResourceAsStream("/application.properties");
would you try this one
java -jar RunableApp4.jar --spring.config.location=<relative-path-to-configs>/InterfaceApp/src/main/resources/ --spring.profiles.active=dev
I`m working on a Spring Boot project and I tried to switch our IDE from STS to Intellij CE. Everything is working fine except when debugging. Whenever I change a Java class, the Spring tries to restart the whole application and fail with the following message:
web - 2018-09-27 08:39:18,494 [restartedMain] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xyz.service.IUserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
web - 2018-09-27 08:39:18,496 [restartedMain] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
web - 2018-09-27 08:39:18,498 [restartedMain] INFO o.a.catalina.core.StandardService - Stopping service [Tomcat]
web - 2018-09-27 08:39:18,524 [restartedMain] INFO o.s.b.a.l.AutoConfigurationReportLoggingInitializer -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
web - 2018-09-27 08:39:18,871 [restartedMain] ERROR o.s.b.d.LoggingFailureAnalysisReporter -
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userService in com.xyz.controller.UserController required a bean of type 'com.xyz.service.IUserService' that could not be found.
Action:
Consider defining a bean of type 'com.xyz.service.IUserService' in your configuration.
Here is some context about the environment:
The spring-boot-devtools 1.5.9 dependency is added to our pom.xml
The option "Preferences->Build, Execution, Deployment->Compiler->Build project automatically" is checked
I've tried debug with the option "cmd+shift+a->Registry->compiler.automake.allow.when.app.running" both checked and unchecked
The IDE version is
IDE version
The spring-boot-starter-parent version is 1.5.9.RELEASE
The following structure describes the class hierarchy:
com.xyz
|-service
| |-IUserService
| |-impl
| |-UserService
|-controller
|-UserController
UserService.java is annotated with #org.springframework.stereotype.Service
UserController has the following field: #Autowired
private IUserService userService
Also, I've tried all the answers from this thread but didn't manage to solve the problem. Has anyone faced this issue? The expected behavior is not restart the whole application and hot swap only the changed artifacts.
Edit:
Here's the UserController sample:
#org.springframework.web.bind.annotation.RestController
#RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserController{
#Autowired
private IUserService userService;
...
}
There is an option in the Spring Boot run configuration to try hot swapping before restarting the application context:
The correct trigger file option will automatically be added to the command line.
I have been trying to Connect from a Grails project to a MySQL Database but I have not managed it yet.
I am working on IntelliJ IDEA 17 with the following versions:
| Grails Version: 3.3.0.RC1
| Groovy Version: 2.4.12
| JVM Version: 1.8.0_131
build.gradle
dependencies{
compile files ("lib/mysql-connector-java-5.1.43-bin")
}
application.yml
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: root
password: ''
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:mysql:3306//localhost/mydatabase
test:
dataSource:
dbCreate: update
url: jdbc:mysql:3306//localhost/mydatabase
production:
dataSource:
dbCreate: none
url: jdbc:mysql:3306//localhost/mydatabase
Errors
"C:\Program Files\Java\jdk1.8.0_131\bin\java" -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Djline.WindowsTerminal.directConsole=false -Dfile.encoding=UTF-8 -classpath C:\Users\Vaggelis\AppData\Local\Temp\classpath.jar org.grails.cli.GrailsCli run-app
|Resolving Dependencies. Please wait...
CONFIGURE SUCCESSFUL
Total time: 3.824 secs
|Running application...
2017-08-07 19:42:52.921 ERROR --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:sun.misc.Launcher$AppClassLoader#18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader#18b4aac2
2017-08-07 19:42:55.391 ERROR --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Unable to load class: com.mysql.jdbc.Driver from ClassLoader:sun.misc.Launcher$AppClassLoader#18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader#18b4aac2
2017-08-07 19:42:55.405 ERROR --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Destroy method on bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor' threw an exception
2017-08-07 19:42:55.431 ERROR --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'methodValidationPostProcessor' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Unsatisfied dependency expressed through method 'methodValidationPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastoreServiceRegistry': Cannot resolve reference to bean 'hibernateDatastore' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.exception.GenericJDBCException: Unable to check JDBC Connection auto-commit in preparation for DDL execution
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastoreServiceRegistry': Cannot resolve reference to bean 'hibernateDatastore' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.exception.GenericJDBCException: Unable to check JDBC Connection auto-commit in preparation for DDL execution
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.exception.GenericJDBCException: Unable to check JDBC Connection auto-commit in preparation for DDL execution
Caused by: org.hibernate.exception.GenericJDBCException: Unable to check JDBC Connection auto-commit in preparation for DDL execution
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':bootRun'.
Process 'command 'C:\Program Files\Java\jdk1.8.0_131\bin\java.exe'' finished with non-zero exit value 1
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error |
Failed to start server (Use --stacktrace to see the full trace)
Process finished with exit code 1
The MySQLConnector is being correctly imported, so somewhere I must have entered wrong data inside the datasource.
In grails 3 dialect is specified under hibernate section and not under datasource.
hibernate:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
I'm using this configuration and it's working fine:
build.gradle
dependencies {
runtime 'mysql:mysql-connector-java:5.1.29'
}
application.yml
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
dataSource:
pooled: true
jmxExport: true
environments:
development:
dataSource:
dbCreate: create-drop
url: "jdbc:mysql://localhost:3306/mydb?autoReconnect=true"
driverClassName: "com.mysql.jdbc.Driver"
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: "yyyyy"
password: "xxxxx"
I fixed a similar issue in my Grails 3.2.9 project by removing the tablePerConcreteClass mapping from two of my abstract domain classes:
static mapping = {
tablePerConcreteClass true
}