Liquibase rollback for customChange - spring

We are using customTaskChange to integrate our customCode and do some operation in our postgress db. I would like to know when rollback will be called for ExampleCustomTaskChange.
<changeSet id="21" author="nvoxland">
<customChange class="liquibase.change.custom.ExampleCustomTaskChange" helloTo="world"/>
</changeSet>
<changeSet id="22" author="nvoxland">
<tagDatabase tag="2022-03-002"/>
</changeSet>
Java code
#Override
public void execute(Database database) throws CustomChangeException {
Scope.getCurrentScope().getLog(getClass()).info("Hello "+getHelloTo());
}
#Override
public void rollback(Database database) throws CustomChangeException, RollbackImpossibleException {
Scope.getCurrentScope().getLog(getClass()).info("Goodbye "+getHelloTo());
}
There are below things which i would like to know:
How rollback in ExampleCustomTaskChange will be called. I tried with cli and ended up with below error. Do we have alternative way to do the rollback in CustomTaskChange.
mvn liquibase:rollback -D liquibase.rollbackTag=2022-03-001
liquibase version : 3.8.9
Maven version : 3.8.4
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.4:rollback (default-cli) on project ExampleCustomTaskChange: Execution default-cli of goal org.liquibase:liquibase-maven-plugin:3.5.4:rollback failed: An API incompatibility was encountered while executing org.liquibase:liquibase-maven-plugin:3.5.4:rollback: java.lang.AbstractMethodError: Receiver class liquibase.logging.core.Slf4jLogger does not define or inherit an implementation of the resolved method abstract info(Ljava/lang/String;)V of interface liquibase.logging.Logger.

Related

H2: Column "SYSDATE" not found after upgrade

I upgraded the version of h2 from 1.4.200 to 2.1.214 and tests fails now because of the use of "SYSDATE" in a liquibase file (we use an Oracle database when the app is deployed).
Content of liquibase file:
<createTable tableName="myTable">
<column defaultValueComputed="SYSDATE" name="CREATION_DATE" type="TIMESTAMP(6)">
<constraints nullable="true" />
</column>
</createTable>
When the liquibase file is loaded to initialize the database for tests, then it fails with this error:
Column "SYSDATE" not found
The executed query is like this:
CREATE TABLE PUBLIC.my_table (..., CREATION_DATE TIMESTAMP(6) DEFAULT SYSDATE,...)
I tried to force the Oracle compatibility mode of H2 like this:
spring:
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=Oracle
I saw that h2, in Oracle compatibility mode, should accept "SYSDATE" keyword but I still have the error.
Do you know what I have to do to solve the issue please?
I found a solution for this error.
For local tests, a configuration of the DataSource was done like this:
#Bean
#Profile(SpringProfiles.H2)
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.setType(EmbeddedDatabaseType.H2) //
.setName("local") //
.build();
}
I had to change it by adding the mode in the name:
#Bean
#Profile(SpringProfiles.H2)
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.setType(EmbeddedDatabaseType.H2) //
.setName("local;MODE=Oracle") //
.build();
}
I found the solution in this link: Does Spring embedded database support different SQL dialects?

How can I provide an own implementation of HttpAuthenticationMechanism in Open Liberty

In a simple app that I run on Open Liberty 21.0.0.8, I have provided an implementation of HttpAuthenticationMechanism:
// imports omitted
#CustomFormAuthenticationMechanismDefinition(
loginToContinue = #LoginToContinue(
loginPage = "/login.xhtml",
errorPage = "",
useForwardToLogin = false))
#ApplicationScoped
public class CustomAuthenticationMechanism implements HttpAuthenticationMechanism {
#Inject
private IdentityStoreHandler identityStoreHandler;
#Override
public AuthenticationStatus validateRequest(HttpServletRequest request,
HttpServletResponse response,
HttpMessageContext context) throws AuthenticationException {
Credential credential = context.getAuthParameters().getCredential();
if (credential != null) {
return context.notifyContainerAboutLogin(identityStoreHandler.validate(credential));
}
else {
return context.doNothing();
}
}
}
I expected Open Liberty to place that implementation of HttpAuthenticationMechanism into service.
However, on startup of Open Liberty a javax.enterprise.inject.spi.DeploymentException is thrown:
[INFO] [ERROR ] CWWKS1925E: The deployment for the dsgvo-management.war module in the dsgvo-management application failed because of multiple HttpAuthenticationMechanism implementations: de.knusperfisch.dsgvo.app.security.control.CustomAuthenticationMechanism, com.ibm.ws.security.javaeesec.cdi.beans.CustomFormAuthenticationMechanism. This failure is likely an application packaging issue. Make sure that each module has only one HttpAuthenticationMechanism implementation.
[INFO] [ERROR ] CWWKZ0004E: An exception occurred while starting the application dsgvo-management. The exception message was: com.ibm.ws.container.service.state.StateChangeException: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
[INFO] Exception 0 :
[INFO] javax.enterprise.inject.spi.DeploymentException: CWWKS1925E: The deployment for the dsgvo-management.war module in the dsgvo-management application failed because of multiple HttpAuthenticationMechanism implementations: de.knusperfisch.dsgvo.app.security.control.CustomAuthenticationMechanism, com.ibm.ws.security.javaeesec.cdi.beans.CustomFormAuthenticationMechanism. This failure is likely an application packaging issue. Make sure that each module has only one HttpAuthenticationMechanism implementation.
[INFO] at com.ibm.ws.security.javaeesec.cdi.extensions.JavaEESecCDIExtension.verifyConfiguration(JavaEESecCDIExtension.java:893)
[INFO] at com.ibm.ws.security.javaeesec.cdi.extensions.JavaEESecCDIExtension.afterBeanDiscovery(JavaEESecCDIExtension.java:173)
The Java EE Security API states that:
An application MAY supply its own HttpAuthenticationMechanism, if desired.
and:
An HttpAuthenticationMechanism must be a CDI bean, and is therefore
visible to the container through CDI if it is packaged in a bean
archive, which generally include Java EE modules and application
archives [...]
It MUST be possible for the definition of an
HttpAuthenticationMechanism to exist within the application archive
[...]
Is there a way in Open Liberty to configure a specific HttpAuthenticationMechanism for an app from an application archive, and if so, how is this done?
At first glance, as the error message indicates, looks like there are multiple HttpAuthMechanisms active which is not allowed. Are there are any apps that are using the #CustomFormAuthenticationMechanismDefinition annotation which would bring in the default com.ibm.ws.security.javaeesec.cdi.beans.CustomFormAuthenticationMechanism AuthMech in addition to your CustomAuthenticationMechanism ?

ClassNotFoundException running Flyway Migrate task with java callback

I am trying to implement a FlyWay java callback. However, flyway doesn't seem to find my class.
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.0-beta:migrate (default-cli) on project odin_build: org.flywaydb.core.api.FlywayException: Unable to instantiate class ch.x.dp.test1 : ch.x.dp.test1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.0-beta:migrate (default-cli) on project odin_build: org.flywaydb.core.api.FlywayException: Unable to instantiate class ch.x.dp.test1 : ch.x.dp.test1
/snip.../
Caused by: java.lang.ClassNotFoundException: ch.x.dp.test1
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
It seems that Flyway cannot find the class.
Here my java class:
package ch.x.dp;
import org.flywaydb.core.api.callback.Callback;
import org.flywaydb.core.api.callback.Context;
import org.flywaydb.core.api.callback.Event;
public class test1 implements Callback {
public test1() {
System.out.println("sldhksjhdkghd");
}
public boolean supports(Event event, Context context) {
return false;
}
public boolean canHandleInTransaction(Event event, Context context) {
return false;
}
public void handle(Event event, Context context) {
}
}
My pom contains the following:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.0.0-beta2</version>
</dependency>
and
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>${flyway.version}</version>
<configuration>
<locations>classpath:ch.x.dp,filesystem:src/main/resources/db/migration</locations>
<callbacks>
<callback>ch.x.dp.test1</callback>
</callbacks>
<snip/>
</plugin>
I have verified that my mvn package calls create a jar in /target that contains my test1 class.
What else could be missing? How can I tell that FlyWay is actually using that jar?

spring boot stater parent 2.0.1 entityManagerFactory Bean creation exception

I am getting following error when I change my spring boot stater parent 1.5.9 RELEASE to 2.0.1 RELEASE
target/surefire-reports
-------------------------------------------------------------------------------
Test set: com.restapispringboot.RestApiSpringbootApplicationTests
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.158 s <<< FAILURE! - in com.restapispringboot.RestApiSpringbootApplicationTests
contextLoads(com.restapispringboot.RestApiSpringbootApplicationTests) Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
Caused by: java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
Caused by: java.lang.ClassNotFoundException: javassist.bytecode.ClassFile
Could it be something in my config that I need to change to make it work?
application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/boot_rest_api
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
# Hibernate ddl auto (create, create-drop, validate, update)
# spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.ddl-auto=create
logging.level.root=DEBUG
Application main
#SpringBootApplication
#EnableJpaRepositories("com.restapispringboot.repo")
#EntityScan("com.restapispringboot.model")
public class RestApiSpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(RestApiSpringbootApplication.class, args);
}
}
Entity
#Entity
#Table(name = "customer")
public class Customer implements Serializable {
// getters and setters
}
Repo
public interface CustomerRepository extends CrudRepository<Customer, Long> {
List<Customer> findByLastName(String lastName);
}
Update
I just notice when I mvn clean install I also get the following errors. But I checked my build path both JRE[JavaSE-1.8] and maven dependencies are build path...
ERROR] error reading /Users/erichuang/.m2/repository/org/aspectj/aspectjweaver/1.8.13/aspectjweaver-1.8.13.jar; invalid CEN header (bad signature)
[ERROR] error reading /Users/erichuang/.m2/repository/org/javassist/javassist/3.22.0-GA/javassist-3.22.0-GA.jar; invalid LOC header (bad signature)
As discussed in the comments, your error says, java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile.
As you were migrating from spring boot version 1.5.9 RELEASE to 2.0.1 RELEASE, there might be some conflict in the javassist jar (3.20.0-GA vs 3.22.0-GA).
So you can clean your maven repo (delete the localRepository) and run your command once again.

SpringBoot Fails now when I switch from spring data neo4j 4.1.3 to 5.0.0

Background
I have an application with spring data neo4j, and I switched from 4.1.3 to 5.0.0.
I believe that I have made all the necessary changes to convert my code over but I still get errors.
My current version of spring boot is
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
Problem
When I run: mvn spring-boot:run in the command line,
I get an error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field actionRepository in myproject.service.ActionServiceImpl required a bean of type 'myproject.repository.ActionRepository' that could not be found.
Action:
Consider defining a bean of type 'myproject.repository.ActionRepository' in your configuration
My myproject.Application.java is currently
#SpringBootApplication
#EnableTransactionManagement
#EnableSwagger2
#EntityScan(basePackages = "myproject.domain")
public class Application {
public static void main(String[] args) {
new SpringApplication(Application.class).run(args);
}
#Bean
public Docket Api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.apiInfo(apiInfo());
}
private springfox.documentation.service.ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Service API")
}
}
And this does not find any of my controllers like myproject.controller.ActionController.java which contains
...
#RestController
#Api(value = "Action", description = "Actions Management API")
#RequestMapping(value = "/api/action")
public class ActionController extends Controller<Action> {
...
Attempt #1
If I add the annotation #ComponentScan({"myproject.request"}) to my Application class, the error goes away, but spring boot cannot load any controllers and as such my Swagger shows no APIs and no controllers are run. This is not the solution. #SpringBootApplication should take care of all this.
Question
How do I reconfig spring boot to start working like it did in version 4.1.3 of spring data neo4j?
UPDATE 1 ATTEMPT #2
I tried adding this annotation to my class Application
#EnableNeo4jRepositories("myproject.repository")
And the error changed to something less clean:
...
2017-10-05 13:19:46.992 ERROR 561 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;
at org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension.postProcess(Neo4jRepositoryConfigurationExtension.java:110) ~[spring-data-neo4j-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:130) ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:83) ~[spring-data-commons-1.12.0.RELEASE.jar:na]
...
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project myproject: An exception occurred while running. null: InvocationTargetException: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; -> [Help 1]
[ERROR]
...
UPDATE 2
In an attempt to use the #EnableNeo4jRepositories("myproject.repository") and bypass the error in Update 1, I tried:
mvn clean install spring-boot:repackage
And it gave a Build Success, but the same error persists:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project myproject: An exception occurred while running. null: InvocationTargetException: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; -
UPDATE 3
I have the new annotation and changed my pom from:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.12.0.RELEASE</version>
</dependency>
to
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
and now mvn spring-boot:run
gives the error:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'getSessionFactory' that could not be found.
Action:
Consider defining a bean named 'getSessionFactory' in your configuration.
Try adding this annotation on your configuration class :
#EnableNeo4jRepositories("myproject.repository")
Update :
I just saw you're on Spring boot 1.4. SDN 5 is only compatible with Spring Boot 2.0.
Details are in the compatibility table.

Resources