I did a Spring Boot application, and use some command line arguments. I read them in services like
#Value("${v}")
private String vertical;
Application works and see value passed from command line. I added same command line arguments to all JUnit tests run configurations
--spring.profiles.active=development --m=keyword --v=Healthcare --i=keyword_update.json
But when I try to run test it crashes with message, that means application context cannot get command line attribute:
2016-05-28 17:16:00.924 ERROR 4204 --- [ main]
o.s.boot.SpringApplicat ion : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error
creating bean wit h name 'application': Injection of autowired
dependencies failed; nested excepti on is
org.springframework.beans.factory.BeanCreationException: Could not
autowir e field: healthjobs.service.Catalog
healthjobs.app.Application.catalog; nested e xception is
org.springframework.beans.factory.BeanCreationException: Error creat
ing bean with name 'catalogImpl': Injection of autowired dependencies
failed; ne sted exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: healthjobs.service.CatalogPage
healthjobs.service.CatalogIm pl.catalogPage; nested exception is
org.springframework.beans.factory.BeanCreati onException: Error
creating bean with name 'catalogPageImpl': Injection of autow ired
dependencies failed; nested exception is
org.springframework.beans.factory. BeanCreationException: Could not
autowire field: private java.lang.String health
jobs.service.CatalogPageImpl.vertical; nested exception is
java.lang.IllegalArgu mentException: Could not resolve placeholder 'v'
in string value "${v}"
Why? How to run tests with command line arguments in spring boot?
PS full stack trace appears too long to attach here. When I run mvn package I get same error about test, but mvn run config does not have ability to input command line arguments. My environment:
Spring Tool Suite Version: 3.7.2.RELEASE Build Id: 201511261048
Platform: Eclipse Mars.1 (4.5.1)
Related
I have created a Grails 3 Restful application, using MySQL as my database. The endpoints are working fine when I hit them with Rest Clients like Postman.
I am using this blog for reference. But it fails when I try to run the command grails url-mappings-report.
Here is the output:
:compileJava NO-SOURCE
:compileGroovy
:buildProperties UP-TO-DATE
:processResources
:classes
:findMainClass
:urlMappingsReport
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Configuring Spring Security REST 2.0.0.M2...
... finished configuring Spring Security REST
... with GORM support
2017-10-01 17:45:24.867 ERROR --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
restTokenValidationFilter
↓
restAuthenticationProvider
↓
tokenStorageService
↓
userDetailsService
┌─────┐
| hibernateDatastore
↑ ↓
| userPasswordEncoderListener
└─────┘
Context failed to load: Error creating bean with name 'restTokenValidationFilter': Cannot resolve reference to bean 'restAuthenticationProvider' while setting bean property 'restAuthenticationProvider'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restAuthenticationProvider': Cannot resolve reference to bean 'tokenStorageService' while setting bean property 'tokenStorageService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenStorageService': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Initialization of bean failed; 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.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userPasswordEncoderListener': Cannot resolve reference to bean 'hibernateDatastore' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'hibernateDatastore': Requested bean is currently in creation: Is there an unresolvable circular reference?
:urlMappingsReport FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':urlMappingsReport'.
> Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' 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.
BUILD FAILED
Total time: 37.453 secs
| Error Command [url-mappings-report] error: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-3.4.1-bin.zip'. (Use --stacktrace to see the full trace)
Grails Version: 3.2.10
Groovy Version: 2.4.10
JVM Version: 1.8.0_131
Try using GORM version >= 6.1
I get the same issue with GORM version 6.0.12.RELEASE
I'm getting the following error when I deploy my application to Tomcat 8. I have MySQL installed on my macbook :
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate com.catalina.productcarried.dao.impl.ProductCarriedDAOImpl.jdbcTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 26 common frames omitted
Here is my application.properties file :
#Database properties local
spring.datasource.url=jdbc:mysql://localhost:3306/simulator?autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
debug=true
Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
Your application.properties is not taken into account for some reason. Note that the driver-classis unnecessary, Spring Boot detects that from the url parameter.
Make sure to review the following:
The mysql driver is defined in your dependencies
The content of the application.properties file you provided in description is in one of the supported locations
I am using docker-compose to set up Artifactory pro with MySQL as the storage database.
Here is my docker-compose.yml
artifactory:
build: artifactory
links:
- mysql
mysql:
image: stain/mysql-for-artifactory
And here is artifactory/Dockerfile
#Dockerfile for Artifactory Pro
FROM stain/artifactory-with-mysql
ADD ./artifactory.war /tomcat/webapps
When I run the command 'docker-compose up' I get the following exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.artifactory.storage.db.DbService org.artifactory.storage.db.security.service.AclServiceImpl.dbService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbServiceImpl': Invocation of init method failed; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
what am I missing?
I recently upgraded to the mysql:mysql-connector-java:5.1.34 connector. My Grails version is 2.2.4. MySQL version is 5.6.10. Upgrading went very smoothly, and the application itself seems to go fine. However, one of my test apps is failing.
The following error happens:
Error Error executing script TestApp:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'transactionManagerPostProcessor':
Initialization of bean failed;
nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'transactionManager':
Cannot resolve reference to bean 'sessionFactory'
while setting bean property 'sessionFactory';
nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory':
Cannot resolve reference to bean 'hibernateProperties'
while setting bean property 'hibernateProperties';
nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'hibernateProperties':
Cannot resolve reference to bean 'dialectDetector'
while setting bean property 'properties' with key [hibernate.dialect];
nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dialectDetector':
Invocation of init method failed;
nested exception is
org.springframework.jdbc.support.MetaDataAccessException:
Error while extracting DatabaseMetaData;
nested exception is java.sql.SQLException:
Access denied for user 'web'#'localhost' (using password: YES)
(Use --stacktrace to see the full trace)
I doublechecked the web user, and as far as I can tell the account is defined properly and has admin privs comparable to root. This has happened both on my development box with my personal database and on our jenkins build system.
I don't see anything in the logs, Running with --stacktrace does not give me any useful information, googling does not show this as a common error.
I am trying to deploy a war file created using grails on tomcat6. The same war files works just alright on my windows machine it does give me following exception with prod linux environment
SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
and
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
I have already gone through
How do I fix the org.springframework.beans.factory.BeanCreationException error in my Grails application?
and
Grails transactionManager exception on Run
but it die not help
Scroll to the end where it says Cannot load JDBC driver class 'com.mysql.jdbc.Driver'. It's usually the case with Grails exceptions that the top-level text is generic and useless, and the real cause is further down near the bottom.
I'm guessing you put the MySQL driver jar in the lib directory, but Grails didn't find it there. You shouldn't use jars unless they're not available in an online repo, and the MySQL driver certainly is. In fact it's the sample entry in BuildConfig.groovy in the dependencies block. Uncomment that, optionally updating to the latest version (5.1.28), and redeploy your war file. Make sure it's there in the file, in WEB-INF/lib