I'm trying to execute tests but only the first call to findBy() is successful. Running with Spring Boot v2.6.7, Spring v5.3.19, hibernate jar = 5.6.8.
Application application = Application.builder()
.appName("APP1")
.productName("PRD1")
.build();
applicationDao.save(application);
Application app1 = applicationDao.findByAppNameIgnoreCaseAndProductNameIgnoreCaseContaining("APP1","PRD");
assertEquals("APP1", app1.getAppName());
The second calls fails in JUnit when called subsequently in the same JUnit test method
Application app2= applicationDao.findByAppNameIgnoreCaseAndProductNameIgnoreCaseContaining("APP1","PRD");
assertEquals("APP1", app2.getAppName());
Error:
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [APP1] did not match expected type [java.lang.Character (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [APP1] did not match expected type [java.lang.Character (n/a)]
Looks like a bug in hibernate. Worked after downgrading hibernate version.
implementation ('org.springframework.boot:spring-boot-starter-data-jpa'){
exclude group: "org.hibernate", module: "hibernate-core"
}
implementation "org.hibernate:hibernate-core:5.6.5.Final"
Related
my dependencies:
implementation 'org.springframework.boot:spring-boot-starter-web:3.0.0-RC1'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.0.0-RC1'
implementation 'org.springframework.boot:spring-boot-starter-data-redis:3.0.0-RC1'
implementation 'org.redisson:redisson-spring-boot-starter:3.17.7'
my error:
Description:
Parameter 0 of constructor in jp.co.netstars.boss.core.api.aspect.RateLimitAspect required a bean of type 'org.redisson.api.RedissonClient' that could not be found.
Action:
Consider defining a bean of type 'org.redisson.api.RedissonClient' in your configuration.
Process finished with exit code 1
it works fine with version 3.0.0-M4.but not in RC1
I have this multi module maven project https://github.com/ghitacornel/testApacheCamel
that i use for playing with Apache Camel.
Here I wrote a route (camel.route.CsvJsonXmlRoute) and a test for the route (camel.CsvJsonXmlRouteTest).
The route works fine.
But when trying to run the test i get "
Caused by: java.lang.IllegalArgumentException: Cannot find RoutesBuilderLoader in classpath supporting file extension: json"
It seems that #SpringBootTest + #CamelSpringBootTest do not get along fine. One does not load Spring components, the other does not load RoutesBuilderLoader.
Any idea on how to make the test working ?
I am trying to configure flyway with kotlin Spring boot, jpa and postgreSQL. My gradle dependencies are:
dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('com.fasterxml.jackson.module:jackson-module-kotlin')
implementation('org.flywaydb:flyway-core')
implementation('com.google.code.gson:gson')
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect")
runtimeOnly('org.postgresql:postgresql')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
My application.properties file is:
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://${JDBC_DATABASE_URL}/jpaTestDatabase
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
flyway.baseline-on-migrate=true
flyway.locations=classpath:src/main/kotlin/db/migration
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=validate
spring.session.store-type=none
Creating tables and entries using jpa and hibernate works as expected.
However a sample migration on an empty database results in:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException:
Found non-empty schema(s) "public" without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
my directory structure is the default one generated by spring initializr and my migrations are in: demo/src/main/kotlin/db/migration
I only have a single migration which is the kotlinized version of the example migration found here which I adapted to look line this:
class V1__Sample : BaseJavaMigration() {
override fun migrate(context: Context?) {
val statement = context?.connection?.prepareStatement(
"""
CREATE TABLE article (
id bigserial primary key,
name varchar(20) NOT NULL,
desc text NOT NULL
);
"""
)
statement.use { it?.execute() }
}
}
What am I missing here? Why does Flyway keep complaining about finding non-empty schema(s) "public" without schema history table, when the database is completelly empty (clean docker image)?
Assuming that you are using spring-boot version 2.
In spring boot 2 the prefix is "spring.flyway" so try adding prefix spring like below.
spring.flyway.baseline-on-migrate = true
OR
spring.flyway.baselineOnMigrate = true
may be you can try mvn flyway:clean && mvn flyway:migrate
Please check the search path of your database, if the public schema (on which flyway is creating its log tables) is not in the first place, it may not be able to find the log table and may complain that schema history is not found...
Please note that, if you are baselining, you need to remove old scripts from the scripts folder, else it will re-attempt it.
Portion of the build file that references spring-cloud-sleuth is provided below.
dependencyManagement {
imports {
//where springCloudVersion = "Dalston.SR5" & springBootVersion = '1.5.9.RELEASE'
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
//in dependencies, added the following line
compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
after adding this dependency, the application fails to start with the following exception (added based on comments)
support.AbstractApplicationContext (AbstractApplicationContext.java:551) -
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'misds':
Could not bind properties to HikariDataSource (prefix=mis.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.validation.BindException: org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanPropertyBindingResult: 4 errors
Field error in object 'mis.datasource' on field 'driverClassName': rejected value [oracle.jdbc.OracleDriver];
codes [methodInvocation.mis.datasource.driverClassName,methodInvocation.driverClassName,methodInvocation.java.lang.String,methodInvocation];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [mis.datasource.driverClassName,driverClassName];
arguments []; default message [driverClassName]]; default message [Property 'driverClassName' threw exception;
nested exception is java.lang.IllegalStateException: The configuration of the pool is sealed once started.
Use HikariConfigMXBean for runtime changes.]
I am using slf4j over log4j for logging framework and the application runs fine when I remove the sleuth dependency.
I noticed that the following 'additional' propertysources are present when spring-cloud dependency is included.
env.MutablePropertySources (MutablePropertySources.java:106) - Adding PropertySource 'springCloudClientHostInfo' with lowest search precedence
env.MutablePropertySources (MutablePropertySources.java:106) - Adding PropertySource 'defaultProperties' with lowest search precedence
env.MutablePropertySources (MutablePropertySources.java:106) - Adding PropertySource 'Management Server' with lowest search precedence
Always check if the latest release train doesn't solve your problems. Honestly, I don't really know which issue is related to this problem :/ Edgware release train is compatible with Boot < 2.0
I have a RESTful service created using Spring MVC. I created an integration test to test my Rest controller, using spring-test mvcmock.
When I am running this test using run as Junit. It is running fine.
However, when the same test is getting executed during mvn install, using surefire plugin. This test is complaining throwing fatal error:
No qualifying bean of type ...
When I checked previous logs it says that it loaded 0 dependecy.
This was the log :
DEBUG XmlBeanDefinitionReader - Loaded 0 bean definitions from location pattern [classpath*:service-test-context.xml]
However, I again run this test class as Junit and I could see "loaded 23 beans at the same log line."
Question: Could you please suggest, what can be the issue?
Note:
This is multi maven module application and dependency of another module is not getting injected.
I was getting same issue, when I was running this test as Junit. Then I added dependent modules in eclipse > build > project and issue got resolved in run as JUnit. Now getting this issue while doing mvn install.
Does your surefire configuration contain an includes parameter?
"A list of elements specifying the tests (by pattern) that should be included in testing. When not specified and when the test parameter is not specified, the default includes will be
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
"
Easy fix is to rename your test runner so that it ends in Test.java. Then
mvn test
will pick it up.
Updated
An alternative is this:
"test:
Specify this parameter to run individual tests by file name, overriding the includes/excludes parameters. Each pattern you specify here will be used to create an include pattern formatted like **/${test}.java, so you can just type "-Dtest=MyTest" to run a single test called "foo/MyTest.java". The test patterns prefixed with a ! will be excluded.
This parameter overrides the includes/excludes parameters, and the TestNG suiteXmlFiles parameter. Since 2.7.3, you can execute a limited number of methods in the test by adding #myMethod or #my*ethod. For example, "-Dtest=MyTest#myMethod". This is supported for junit 4.x and testNg.
Since 2.19 a complex syntax is supported in one parameter (JUnit 4, JUnit 4.7+, TestNG):
"-Dtest=???Test, !Unstable*, pkg/**/Ci*leTest.java, Test#testOne+testTwo?????, #fast*+slowTest"
"-Dtest=Basic*, !%regex[..Unstable.], !%regex[..MyTest.class#one.|two.], %regex[#fast.|slow.*]"
The Parameterized JUnit runner describes test methods using an index in brackets, so the non-regex method pattern would become: #testMethod[]. If using #Parameters(name="{index}: fib({0})={1}") and selecting the index e.g. 5 in pattern, the non-regex method pattern would become #testMethod[5:].
Type: java.lang.String
Required: No
User Property: test
"
So if your test runner was named foo/MyVeryOwnRunner.java you could do the following
mvn clean test -Dtest=MyVeryOwnRunner