The problem is simple: liquibase fails to find my changeset sqlfile to run it against my db.
Paths are as follows:
SqlCl: C:\Oracle\sqlcl
No CLASSPATH is defined in user env variables
Main changelog file: C:\repos\odb\db-scripts\main.yaml
Changeset sqlfile: C:\repos\odb\db-scripts\test.sql
main.yaml contains:
databaseChangeLog:
- changeSet:
id: 1
author: some_author
changes:
- sqlFile:
path: test.sql
splitStatements: true
endDelimiter: /
stripComments: true
test.sql contains:
create or replace view asdas
as
select 1 val from dual
/
What I get when I run liquibase update via sqlcl:
C:\repos\odb\db-scripts>sql stat_adm#dev-odb1
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
SQLcl: Release 20.4 Production on Tue May 25 18:03:50 2021
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Password? (**********?) ********
Last Successful login time: Tue May 25 2021 18:03:55 +03:00
Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.7.0.0.0
SQL> lb update -changelog main.yaml
Processing has failed for your request.
liquibase.exception.UnexpectedLiquibaseException: java.io.IOException: The file test.sql was not found in
- C:\Oracle\jdbc\lib\ojdbc8.jar
- C:\Oracle\jlib\orai18n-mapping.jar
- C:\Oracle\jlib\orai18n-utility.jar
- C:\Oracle\jlib\orai18n.jar
- C:\Oracle\lib\ojdbc8.jar
- C:\Oracle\modules\oracle.xdk\xmlparserv2.jar
- C:\Oracle\rdbms\jlib\xdb6.jar
- C:\Oracle\sqlcl\lib
- C:\Oracle\sqlcl\lib\ST4.jar
- C:\Oracle\sqlcl\lib\antlr-runtime.jar
- C:\Oracle\sqlcl\lib\commons-codec.jar
- C:\Oracle\sqlcl\lib\commons-logging.jar
- C:\Oracle\sqlcl\lib\dbtools-common.jar
- C:\Oracle\sqlcl\lib\dbtools-data.jar
- C:\Oracle\sqlcl\lib\dbtools-http.jar
- C:\Oracle\sqlcl\lib\dbtools-net.jar
- C:\Oracle\sqlcl\lib\dbtools-sqlcl.jar
- C:\Oracle\sqlcl\lib\ext
- C:\Oracle\sqlcl\lib\ext\dbtools-liquibase.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-modeler-cli-ext.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-modeler-common.jar
- C:\Oracle\sqlcl\lib\ext\liquibase-core.jar
- C:\Oracle\sqlcl\lib\ext\migration-core.jar
- C:\Oracle\sqlcl\lib\ext\migration-postgres.jar
- C:\Oracle\sqlcl\lib\ext\snakeyaml-1.12.jar
- C:\Oracle\sqlcl\lib\guava.jar
- C:\Oracle\sqlcl\lib\httpclient.jar
- C:\Oracle\sqlcl\lib\httpcore.jar
- C:\Oracle\sqlcl\lib\httpmime.jar
- C:\Oracle\sqlcl\lib\jackson-annotations.jar
- C:\Oracle\sqlcl\lib\jackson-core.jar
- C:\Oracle\sqlcl\lib\jackson-jr-objects.jar
- C:\Oracle\sqlcl\lib\jackson-jr-stree.jar
- C:\Oracle\sqlcl\lib\jansi.jar
- C:\Oracle\sqlcl\lib\javax.json.jar
- C:\Oracle\sqlcl\lib\jdbcrest.jar
- C:\Oracle\sqlcl\lib\jline.jar
- C:\Oracle\sqlcl\lib\ojdbc8.jar
- C:\Oracle\sqlcl\lib\oraclepki.jar
- C:\Oracle\sqlcl\lib\orai18n-collation.jar
- C:\Oracle\sqlcl\lib\orai18n-mapping.jar
- C:\Oracle\sqlcl\lib\orai18n-servlet.jar
- C:\Oracle\sqlcl\lib\orai18n-utility.jar
- C:\Oracle\sqlcl\lib\orai18n.jar
- C:\Oracle\sqlcl\lib\orajsoda.jar
- C:\Oracle\sqlcl\lib\osdt_cert.jar
- C:\Oracle\sqlcl\lib\osdt_core.jar
- C:\Oracle\sqlcl\lib\slf4j-api.jar
- C:\Oracle\sqlcl\lib\slf4j-jdk14.jar
- C:\Oracle\sqlcl\lib\sshd-common.jar
- C:\Oracle\sqlcl\lib\sshd-contrib.jar
- C:\Oracle\sqlcl\lib\sshd-core.jar
- C:\Oracle\sqlcl\lib\xdb6.jar
- C:\Oracle\sqlcl\lib\xmlparserv2-sans-jaxp-services.jar
- C:\Oracle\sqlcl\lib\xmlparserv2.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\access-bridge-64.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\cldrdata.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\dnsns.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\jaccess.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\jfxrt.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\localedata.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\nashorn.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunec.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunjce_provider.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunmscapi.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunpkcs11.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\zipfs.jar
- C:\jdbc\lib\ojdbc8.jar
- C:\jlib\orai18n-mapping.jar
- C:\jlib\orai18n-utility.jar
- C:\jlib\orai18n.jar
- C:\rdbms\jlib\xdb6.jar
- C:\repos\odb\db-scripts\ST4-4.3.1.jar
- C:\repos\odb\db-scripts\antlr-runtime-3.5.2.jar
- C:\repos\odb\db-scripts\commons-codec-1.15.jar
- C:\repos\odb\db-scripts\commons-logging-1.2.0.0.1.jar
- C:\repos\odb\db-scripts\dbtools-common-20.4.1.jar
- C:\repos\odb\db-scripts\dbtools-data-20.4.1.jar
- C:\repos\odb\db-scripts\dbtools-http-20.4.1.jar
- C:\repos\odb\db-scripts\dbtools-net-20.4.1.jar
- C:\repos\odb\db-scripts\dbtools-sqlcl-20.4.1.jar
- C:\repos\odb\db-scripts\guava-30.0-jre.jar
- C:\repos\odb\db-scripts\httpclient-4.5.13.jar
- C:\repos\odb\db-scripts\httpcore-4.4.13.jar
- C:\repos\odb\db-scripts\httpmime-4.5.13.jar
- C:\repos\odb\db-scripts\jackson-annotations-2.11.3.jar
- C:\repos\odb\db-scripts\jackson-core-2.11.3.jar
- C:\repos\odb\db-scripts\jackson-jr-objects-2.11.3.jar
- C:\repos\odb\db-scripts\jackson-jr-stree-2.11.3.jar
- C:\repos\odb\db-scripts\jansi-1.18.jar
- C:\repos\odb\db-scripts\javax.activation-api-1.2.0.jar
- C:\repos\odb\db-scripts\javax.json-1.1.4.jar
- C:\repos\odb\db-scripts\jaxb-api-2.4.0-b180830.0359.jar
- C:\repos\odb\db-scripts\jdbcrest-20.4.1.jar
- C:\repos\odb\db-scripts\jline-2.14.6.jar
- C:\repos\odb\db-scripts\low-level-api-13.0.0.jar
- C:\repos\odb\db-scripts\ojdbc8-21.0.0.jar
- C:\repos\odb\db-scripts\oraclepki-21.0.0.jar
- C:\repos\odb\db-scripts\orai18n-21.0.0.jar
- C:\repos\odb\db-scripts\orai18n-mapping-21.0.0.jar
- C:\repos\odb\db-scripts\orai18n-utility-21.0.0.jar
- C:\repos\odb\db-scripts\orajsoda-1.1.3.jar
- C:\repos\odb\db-scripts\osdt_cert-21.0.0.jar
- C:\repos\odb\db-scripts\osdt_core-21.0.0.jar
- C:\repos\odb\db-scripts\slf4j-api-1.7.30.jar
- C:\repos\odb\db-scripts\slf4j-jdk14-1.7.30.jar
- C:\repos\odb\db-scripts\sshd-common-2.5.0.jar
- C:\repos\odb\db-scripts\sshd-contrib-2.5.0.jar
- C:\repos\odb\db-scripts\sshd-core-2.5.0.jar
- C:\repos\odb\db-scripts\sshd-scp-2.5.0.jar
- C:\repos\odb\db-scripts\sshd-sftp-2.5.0.jar
- C:\repos\odb\db-scripts\ucp-21.0.0.jar
- C:\repos\odb\db-scripts\xdb6-21.0.0.jar
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
SQL>
Somehow it picks up C:\repos\odb\db-scripts\ path but there are just imaginary jar that don't persist there. By the way paths C:\jdbc\lib\, C:\jlib\, C:\rdbms\jlib\xdb6.jar don't even exist on my machine.
Adding relativeToChangelogFile: true to main.yaml doesn't help.
How should I tell sqlcl to pick up test.sql file from the current directory or at least provide a full path?
EDIT:
I decided to run it using liquibase itself. I downloaded liquibase installation zip archive and took liquibase.bat from it and put it into sqlcl installation path. Then I added this path to my PATH variable so that I can call it from command line.
Also I created in C:\repos\odb\db-scripts\ file liquibase.properties with the following contents:
changeLogFile: main.yaml
driver: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:#mega-db-host:1521/odb1
username: usr
password: pwd
Note that C:\repos\odb\db-scripts\ is the same dir for test.sql and main.yaml. After that I've run liquibase:
C:\repos\odb\db-scripts>liquibase update
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
####################################################
## _ _ _ _ ##
## | | (_) (_) | ##
## | | _ __ _ _ _ _| |__ __ _ ___ ___ ##
## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ ##
## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ ##
## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| ##
## | | ##
## |_| ##
## ##
## Get documentation at docs.liquibase.com ##
## Get certified courses at learn.liquibase.com ##
## Get advanced features and support at ##
## liquibase.com/support ##
## ##
####################################################
Starting Liquibase at 10:11:50 (version 4.1.1 #0 built at 2020-11-02 16:02+0000)
ScriptRunner Executing: create or replace view asdas
as
select 1 val from dualLiquibase Executed:create or replace view asdas
as
select 1 val from dual
Liquibase: Update has been successful.
See: no errors. After that I decided to set non-existing path to sql file and guess what I've got:
C:\repos\odb\db-scripts>liquibase update
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
####################################################
## _ _ _ _ ##
## | | (_) (_) | ##
## | | _ __ _ _ _ _| |__ __ _ ___ ___ ##
## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ ##
## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ ##
## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| ##
## | | ##
## |_| ##
## ##
## Get documentation at docs.liquibase.com ##
## Get certified courses at learn.liquibase.com ##
## Get advanced features and support at ##
## liquibase.com/support ##
## ##
####################################################
Starting Liquibase at 10:12:44 (version 4.1.1 #0 built at 2020-11-02 16:02+0000)
Unexpected error running Liquibase: java.io.IOException: The file not_exists.sql was not found in
- C:\Oracle\sqlcl\lib
- C:\Oracle\sqlcl\lib\ST4.jar
- C:\Oracle\sqlcl\lib\antlr-runtime.jar
- C:\Oracle\sqlcl\lib\commons-codec.jar
- C:\Oracle\sqlcl\lib\commons-logging.jar
- C:\Oracle\sqlcl\lib\dbtools-common.jar
- C:\Oracle\sqlcl\lib\dbtools-data.jar
- C:\Oracle\sqlcl\lib\dbtools-http.jar
- C:\Oracle\sqlcl\lib\dbtools-net.jar
- C:\Oracle\sqlcl\lib\dbtools-sqlcl.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-liquibase.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-modeler-cli-ext.jar
- C:\Oracle\sqlcl\lib\ext\dbtools-modeler-common.jar
- C:\Oracle\sqlcl\lib\ext\liquibase-core.jar
- C:\Oracle\sqlcl\lib\ext\migration-core.jar
- C:\Oracle\sqlcl\lib\ext\migration-postgres.jar
- C:\Oracle\sqlcl\lib\ext\snakeyaml-1.12.jar
- C:\Oracle\sqlcl\lib\guava.jar
- C:\Oracle\sqlcl\lib\httpclient.jar
- C:\Oracle\sqlcl\lib\httpcore.jar
- C:\Oracle\sqlcl\lib\httpmime.jar
- C:\Oracle\sqlcl\lib\jackson-annotations.jar
- C:\Oracle\sqlcl\lib\jackson-core.jar
- C:\Oracle\sqlcl\lib\jackson-jr-objects.jar
- C:\Oracle\sqlcl\lib\jackson-jr-stree.jar
- C:\Oracle\sqlcl\lib\jansi.jar
- C:\Oracle\sqlcl\lib\javax.activation-api.jar
- C:\Oracle\sqlcl\lib\javax.json.jar
- C:\Oracle\sqlcl\lib\jaxb-api.jar
- C:\Oracle\sqlcl\lib\jdbcrest.jar
- C:\Oracle\sqlcl\lib\jline.jar
- C:\Oracle\sqlcl\lib\low-level-api.jar
- C:\Oracle\sqlcl\lib\ojdbc8.jar
- C:\Oracle\sqlcl\lib\oraclepki.jar
- C:\Oracle\sqlcl\lib\orai18n-mapping.jar
- C:\Oracle\sqlcl\lib\orai18n-utility.jar
- C:\Oracle\sqlcl\lib\orai18n.jar
- C:\Oracle\sqlcl\lib\orajsoda.jar
- C:\Oracle\sqlcl\lib\osdt_cert.jar
- C:\Oracle\sqlcl\lib\osdt_core.jar
- C:\Oracle\sqlcl\lib\slf4j-api.jar
- C:\Oracle\sqlcl\lib\slf4j-jdk14.jar
- C:\Oracle\sqlcl\lib\snakeyaml-1.12.jar
- C:\Oracle\sqlcl\lib\sshd-common.jar
- C:\Oracle\sqlcl\lib\sshd-contrib.jar
- C:\Oracle\sqlcl\lib\sshd-core.jar
- C:\Oracle\sqlcl\lib\sshd-scp.jar
- C:\Oracle\sqlcl\lib\sshd-sftp.jar
- C:\Oracle\sqlcl\lib\ucp.jar
- C:\Oracle\sqlcl\lib\xdb6.jar
- C:\Oracle\sqlcl\lib\xmlparserv2-sans-jaxp-services.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\access-bridge-64.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\cldrdata.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\dnsns.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\jaccess.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\jfxrt.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\localedata.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\nashorn.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunec.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunjce_provider.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunmscapi.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\sunpkcs11.jar
- C:\Program Files\Java\jre1.8.0_271\lib\ext\zipfs.jar
- C:\repos\odb\db-scripts
- C:\repos\odb\db-scripts\.
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
For more information, please use the --logLevel flag
Note that liquibase added the current directory on the lookup list. And that's why it managed to find my test.sql file. Looks like sqlcl is the one who fails to use the current path for SQL files.
Related
After upgrading Spring Cloud libraries to newest version Spring Cloud Config client behaves differently in terms of logging.
In previous version, whenever Spring Cloud Config server was unavailable, I could see log:
Connect Timeout Exception on Url - http://localhost:8888/. Will be trying the next url if available
Currently there's no logs, application simply hangs. After Config Server is available, app also starts an emits all logs at once. It looks like it's caching somehow all logs istead of outputting it immediately.
[INFO] --- spring-boot-maven-plugin:2.5.4:run (default-cli) # gateway-service ---
[INFO] Attaching agents: []
2021-10-07 18:37:02,746 main ERROR Unrecognized format specifier [entityId]
2021-10-07 18:37:02,747 main ERROR Unrecognized conversion specifier [entityId] starting at position 146 in conversion pattern.
2021-10-07 18:38:36,172 main ERROR Unrecognized format specifier [entityId]
2021-10-07 18:38:36,172 main ERROR Unrecognized conversion specifier [entityId] starting at position 147 in conversion pattern.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.4)
2021-10-07 18:38:36.340 INFO 80607 --- [ main] c.y.g.GatewayApplication [%entityId] : Starting GatewayApplication using Java 11.0.12 on ...
In the example above, I was waiting for 30s, before starting Config Server (see timestamps). What is wrong?
error[E0282]: type annotations needed
--> /home/amiya/.cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
|
541 | let accuracy = P::ACCURACY.saturated_into();
| ^^^^^^^^ consider giving `accuracy` a type
...
1595 | / implement_fixed!(
1596 | | FixedI64,
1597 | | test_fixed_i64,
1598 | | i64,
... |
1601 | | "_Fixed Point 64 bits signed, range = [-9223372036.854775808, 9223372036.854775807]_",
1602 | | );
| |__- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0282]: type annotations needed
--> /home/amiya/.cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
|
541 | let accuracy = P::ACCURACY.saturated_into();
| ^^^^^^^^ consider giving `accuracy` a type
...
1604 | / implement_fixed!(
1605 | | FixedI128,
1606 | | test_fixed_i128,
1607 | | i128,
... |
1611 | | [-170141183460469231731.687303715884105728, 170141183460469231731.687303715884105727]_",
1612 | | );
| |__- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0282]: type annotations needed
--> /home/amiya/.cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
|
541 | let accuracy = P::ACCURACY.saturated_into();
| ^^^^^^^^ consider giving `accuracy` a type
I am using Ubuntu 20.04, its giving same error for both
WASM_BUILD_TOOLCHAIN=nightly-2020-08-23 cargo build --release
and
WASM_BUILD_TOOLCHAIN=nightly-2020-10-05 cargo build --release
https://github.com/substrate-developer-hub/substrate-node-template/blob/4d97032c11b8c65936e53a61607d4522d45a29ea/Makefile
https://stackoverflow.com/a/63993797/1566713
Note: This should be fixed soon in substrate v2.0.1
For now you may need to downgrade your toolchain: https://substrate.dev/docs/en/knowledgebase/getting-started/#downgrading-rust-nightly
The known working date for me is 2020-10-5 for all toolchains, and the default uses nightly from that date.
I am on Ubuntu 20.04LTS as well, and use:
$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: ....
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu
nightly-2020-10-05-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
installed targets for active toolchain
--------------------------------------
wasm32-unknown-unknown
x86_64-unknown-linux-gnu
active toolchain
----------------
nightly-2020-10-05-x86_64-unknown-linux-gnu (default)
rustc 1.49.0-nightly (beb5ae474 2020-10-04)
Here's the issue https://github.com/paritytech/substrate/issues/7287
Solve with just this single line
rustup default nightly-2020-10-06 && rustup target add wasm32-unknown-unknown
This was fixed already in v2.0.1, try deleting the project and cloning again using the following command.
git clone -b v2.0.1 --depth 1 https://github.com/substrate-developer-hub/substrate-node-template
I want to include a folder and its contents in the test resources for a Gradle project.
Let's say I have the following project structure:
projectRoot
| - src
| | - main
| | \ - java
| \ - test
| \ - java
\ - vars
\ - *.groovy files
The vars folder contains several *.groovy files that I want to be included in the test resources when the project is built. However, the test resources must include the vars folder, not just the contents inside that folder.
If I add the following block to my buid.gradle file, it only puts the contents of that folder in the test resources:
sourceSets {
test {
resources {
srcDir "vars"
}
}
}
This makes the build/resources/test directory contain the contents of the vars folder, but not the vars folder itself:
projectRoot
| - build
| \ - resources
| \ - test
| \ - *.groovy files
| - src
| | - main
| | \ - java
| \ - test
| \ - java
\ - vars
\ - *.groovy files
However, what I really am after is this:
projectRoot
| - build
| \ - resources
| \ - test
| \ - vars
| \ - *.groovy files
| - src
| | - main
| | \ - java
| \ - test
| \ - java
\ - vars
\ - *.groovy files
(Notice how the vars folder is listed in the build/resources/test folder)
How do I do this?
Note: I cannot make changes to the directory structure of the project (i.e. the vars folder cannot have any sub-directories, and it must be top level).
Perhaps something like this will work:
task copyConfig(type: Copy) {
from "${project.projectDir}/vars/*.*"
into "${project.projectDir}/.build/resources/test/vars"
dependsOn processTestResources
}
copyConfig.mustRunAfter(processTestResources)
testClasses.dependsOn copyConfig
testClasses.mustRunAfter copyConfig
I have Spring Boot web application and want to display a version number in my application. The version number should be something like v1.2.3#BUILD_NUMBER, where BUILD_NUMBER is the build number from Jenkins. How can I achieve this?
First, let's make sure Gradle knows about the build number. Jenkins makes it available with an environment variable. We can put it in the normal version field in the Gradle project:
version = "1.0-" + (System.getenv("BUILD_NUMBER") ?: "SNAPSHOT")
From here we have to put it into a file that your application can read. There are two good ways to do this, and I usually use both at the same time.
First, we update the standard MANIFEST.MF file in the final jar:
bootJar {
manifest {
attributes(
"Implementation-Title": project.name,
"Implementation-Version": project.version
)
}
}
By default, Spring Boot will print a banner on start-up and it reads those attributes and prints them out. You can customize the banner, but until you do it should look something like this:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.5.RELEASE)
2020-11-06 16:00:56.394 INFO 3144 --- [main] com.example.App : Starting App v1.0-SNAPSHOT on PF18RJAD with PID 3144 (C:\Work\Temp\buildinfo-example\app\build\libs\app-1.0-SNAPSHOT.jar started by bmv in C:\Work\Temp\buildinfo-example\app)
2020-11-06 16:00:56.398 INFO 3144 --- [main] com.example.App : No active profile set, falling back to default profiles: default
2020-11-06 16:00:57.181 INFO 3144 --- [main] com.example.App : Started App in 1.292 seconds (JVM running for 1.908)
Notice the line "Starting App v1.0-SNAPSHOT", where "SNAPSHOT" will be replaced with the environment variable if present.
But note that because MANIFEST.INF is only created as part of the jar, it will not show in tests or by running the bootRun task. You have to run the final "boot jar" (e.g. java -jar build/libs/app-1.0-SNAPSHOT.jar).
Secondly, you can use the BuildInfo task. This enables Actuator to read more details about the build, and makes it easier for you to programmatically query them:
springBoot {
buildInfo()
}
This will generate a file META-INF/build-info.properties in your application with build information like version, artifact name or custom values. You can query them by injecting a BuildProperties instance:
#Autowired
BuildProperties buildProperties;
Use it to get information about the build:
public void greet() {
System.out.println("Hello version: " + buildProperties.getVersion());
}
It should output:
Hello version: 1.0-SNAPSHOT
If you use Actuator, it will also pick up information from the build properties file.
I have registered a MySecurityEventListener in my Grails app to set a login count after a user has been logged in.
MySecurityEventListener class:
class MySecurityEventListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent>, LogoutHandler {
/**
* Handler for after login.
*/
#Override
public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
User.withNewSession {
User user = User.get(event.authentication.principal.id)
user.lastLoginDate = new Date() // set the last login date
user.loginCount += 1 // increase the login count
user.isLoggedIn = true
user.save(flush: true)
}
}
/**
* Handler for after logout.
*/
#Override
public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
User.withNewSession {
User user = User.get(authentication.principal.id)
user.isLoggedIn = false
user.save(flush: true)
}
}
}
Sometimes when a user loggs in I get the following error:
| Error 2013-07-03 13:40:56,306 [http-nio-8080-exec-1]
ERROR events.PatchedDefaultFlushEventListener -
Could not synchronize database state with session Message:
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [demo.User#ffd93c5639b54405bf]
Line | Method
->> 38 | doCall in demo.MySecurityEventListener$_onApplicationEvent_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 33 | onApplicationEvent in demo.MySecurityEventListener
| 1145 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . in java.lang.Thread
2013-07-03 13:40:56,551 [http-nio-8080-exec-1] INFO cpr.SessionSupport - Session created
2013-07-03 13:40:56,554 [http-nio-8080-exec-2] INFO cpr.SessionSupport - Session created
| Error 2013-07-03 13:40:56,554 [http-nio-8080-exec-1] ERROR [/demo].[gsp] - Servlet.service() for servlet [gsp] in context with path [/demo] threw exception
Message: Object of class [demo.User] with identifier [ffd93c5639b54405bf]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [demo.User#ffd93c5639b54405bf]
Line | Method
->> 38 | doCall in demo.MySecurityEventListener$_onApplicationEvent_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 33 | onApplicationEvent in demo.MySecurityEventListener
| 1145 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . in java.lang.Thread
Caused by StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [demo.User#ffd93c5639b54405bf]
->> 38 | doCall in demo.MySecurityEventListener$_onApplicationEvent_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 33 | onApplicationEvent in demo.MySecurityEventListener
| 1145 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . in java.lang.Thread
How do I have to fix this error?
withTransaction provides access to the underlying transaction. If needed a control over transaction rollback you can use it.
withSession uses the default session provided by SessionFactory. If needed a control over sesion then use it.
Looking at your example, I would vouch for withTransaction (the simplest one).