I have been trying to integrate h2 DB with spring boot application and I am getting the following error when trying to connect from the h2-console
Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)
org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200]
I tried adding the following properties to the application.properties file:
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create
It still does not seem to work.
This is how my build.gradle file looks like
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.data:spring-data-jpa'
runtimeOnly 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
It works as expected if you replace the line
implementation 'org.springframework.data:spring-data-jpa'
with
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
in build.gradle if you make sure that the field JDBC URL in the login mask has the value jdbc:h2:mem:testdb.
You get the correct build.gradle if you use the Spring Initializr and add
Lombok
Spring Data JPA
H2 Database
Spring Web
If you want to add dependencies to a project that was originally created with the Spring Initializr, it's usually a good idea to go back to https://start.spring.io/, add all dependencies, hit the Explore button, and copy & paste the generated build.gradle into the existing project.
Related
I have the following gradle settings:
plugins {
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
}
How can I lock or specify exactly the versions of all the dependencies libs, how do I check the compatibility with the other libs and chose the most new and updated ones?
as I understand - spring boot doesn't need spring framework specified?
checked other Stackoverflow posts.
checked compatibility matrix.
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:3.0.0"
}
}
solved the issue.
i am trying to get actuator refresh to work and i cant seem to get it to work. I keep getting 404. The application is basic hello world, have not added anything other than a controller which responds with "Hello". That all works.. but i cant seem to get access to the health or info endpoints.. i read these should be available
my versions are:
Gradle:
plugins {
id 'org.springframework.boot' version '2.7.3'
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2021.0.3")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.projectlombok:lombok:1.18.22'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.7.3'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
Tried:
Application.properties
server:
port: 9999
server:
port: 9999
management:
health:
refresh:
enabled: true
This too:
management:
info:
env:
enabled: true
i dont think the last one is even available in 2.7
Im using the latest actuator which is 2.7.3, and the url im trying is
http://localhost:9999/actuator/health
I'm upgrading our application's spring boot version from 2.6 to 2.7. I had a similar problem, the actuator endpoint did not show up when I changed spring-boot-starter-actuator version from 2.6.11 to any 2.7.* version.
But when I added spring-boot-actuator-autoconfigure dependency manually, the actuator started to work as before.
So try to add org.springframework.boot:spring-boot-actuator-autoconfigure to your to dependencies.
I cant figure out why this solves the problem. It should work without adding this dependency manually. Maybe the changes in the spring autoconfiguration somehow affected the actuator auto configuration.
An old application of mine is a Java 8 Enterprise mololith and i want to migrate it.
I want to migrate it into a spring boot project including primefaces,
myfaces and omnifaces by using joinfaces and split it into smaller parts (multi-modules-project)
for better maintainance.
So i split the project into the following modules to became an working prototype:
Short description of the modules:
Common / ComDb : Here are only generated JPA entities / classed directly from the database which classes can be used by all modules
Libraries / LibPrimeFaces : Here are only the latest primefaces elite JAR's which should be used in SpringBoot
Libraries / LibPrimeFacesTheme : Here are a buyed primefaces theme which will be bundeled and included by a generated JAR.
Services / * : Each spring boot service which should be used is located here, so it can be used in the main application or from an external service over REST
Application : Here is the spring boot application which should include all of the things above - even a runnable jar-file at last
The problem now for me is the usage of gradle which is completly new for me:
I dont't know how to integrate joinfaces in combination with my buyed primefaces-8.0.5.jar from elite subscription, omnifaces 3 and myfaces by using gradle.
The most manuals are for maven, but it seems that they are not working for gradle if i
convert the scripts.
Currently the whole project compiles and start without any errors but now i am at the point where i can't find a working example of using joinfaces and gradle in a multi module environment like mine.
Here are the main gradle-scripts:
The root-scripts:
gradle.properties (Holding the versions):
VersionSpringBoot=2.3.5.RELEASE
VersionSpringDependencyManagement=1.0.10.RELEASE
VersionPrimeFaces=8.0.5
settings.gradle (includes and names):
rootProject.name = 'EcoCalcDD4Web'
include 'Common:ComDb'
include 'Libraries:LibPrimeFaces'
include 'Services:ServiceConfigWebManagement'
include 'Application'
build.gradle (Main build file):
buildscript {
repositories {
mavenCentral()
maven {
url './Libraries/LibPrimeFaces'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${VersionSpringBoot}")
}
}
allprojects {
group = 'com.skf.rocket'
version = '1.0.0'
repositories {
mavenCentral()
maven {
url './Libraries/LibPrimeFaces'
}
}
}
subprojects {
apply plugin: 'java-library'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
maven {
url './Libraries/LibPrimeFaces'
}
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${VersionSpringBoot}")
}
}
dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
}
And here the application build.gradle - file where JoinFaces should be used with my primefaces, omnifaces and myfaces.
Here i don't know what to add to get all started with joinfaces:
apply plugin: 'org.springframework.boot'
bootJar {
mainClassName = "com.skf.rocket.EcoCalcDd4WebRocket"
}
// Maven dependencies
dependencies {
// Internal dependencies
api project(':Common:ComDb')
// Implementation project('Libraries:LibPrimeFacesTheme')
api project(':Services:ServiceConfigWebManagement')
// External dependencies
// JoinFaces + MyFaces + PrimeFaces - TODO ??
// Development tools with HotReDeploy
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// Automatically configuration
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
// Lombok - Utility
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Global cache
implementation 'org.springframework.boot:spring-boot-starter-cache'
// Data access + MS SQL driver
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
// Data validation
implementation 'org.springframework.boot:spring-boot-starter-validation'
// Web + RestService
implementation 'org.springframework.boot:spring-boot-starter-web'
// Session management
implementation 'org.springframework.session:spring-session-core'
// Boot Acturator - Application monitoring and alive checks
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
// Unit test
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
At first, you should have a look at these resources:
https://docs.gradle.org/current/userguide/intro_multi_project_builds.html
https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver
https://docs.joinfaces.org/4.3.4/reference/#_gradle
https://docs.joinfaces.org/4.3.4/reference/#_example_using_myfaces_instead_of_mojarra
https://github.com/joinfaces/joinfaces-gradle-jar-example
To get started with JoinFaces, you need a dependency on org.joinfaces:jsf-spring-boot-starter.
Because you want to use MyFaces instead of Mojarra, you have to exclude it and pull MyFaces instead.
I'd start with these dependencies:
implementation ("org.joinfaces:jsf-spring-boot-starter") {
exclude module: "mojarra-spring-boot-starter"
}
implementation "org.joinfaces:myfaces-spring-boot-starter"
implementation "org.joinfaces:omnifaces1-spring-boot-starter"
Can anyone show me or point me to a spring boot gradle project that does not make use of the spring boot gradle plugin.
I'm looking for something like a spring boot starter web hello world example that doesn't use the gradle plugin.
I can't imagine that the plugin is a requirement, but a search for examples all seem to lean on the gradle plugin, which lets just say is not an option in my environment, and no I can't switch to maven either.
Ideally the gradle build would work by adding something like the following:
gradle.properties
springBootVersion=2.1.3.RELEASE
build.gradle
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
}
I used the spring dependency management plugin, and it works
buildscript {
ext {
springDepManagementVersion = '1.0.10.RELEASE'
springBootVersion = '2.6.6'
springCloudVersion = "2021.0.1"
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:${springDepManagementVersion}"
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-sleuth"
implementation 'org.springframework.boot:spring-boot-starter-json'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
...
}
I can't use spring boot gradle plugin, since I can only use gradle 6.7.1, while spring boot gradle plugin requires gradle version at least 6.8 to support spring boot 2.6. I was inspired by the spring cloud bom solution.
Is it possible to configure or autowire a JWE key selector for a spring boot 2.0 application with spring security 5.x.x to be able to decrypt the id_oken received from an OpenId connect provider?
The JWS Keys can be defined by the spring security oauth2 client registration properties. But I did not find a way for specifing the JWEKeySelector for the JWTDecoder used by spring security oauth.
Thanks in advance!
dependencies:
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
ext['thymeleaf.version'] = '3.0.9.RELEASE'
dependencies {
compile 'org.springframework.security:spring-security-config'
compile 'org.springframework.security:spring-security-oauth2-client'
compile 'org.springframework.security:spring-security-oauth2-jose'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity4'
compile 'io.projectreactor.ipc:reactor-netty'
compile 'org.springframework:spring-webflux'
compile 'org.webjars:jquery:3.3.1-1'
compile 'org.webjars:bootstrap:4.0.0-1'
compile 'org.webjars:webjars-locator:0.32'
testCompile 'org.springframework.security:spring-security-test'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}