Can't Set Up MySQL Connection: CLIENT_PLUGIN_AUTH is required - mysql

was trying to connect to mysql server with spring boot but getting this error: com.mysql.cj.exceptions.UnableToConnectException: CLIENT_PLUGIN_AUTH is required
application.properties:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=shafin
spring.datasource.password=admin
spring.datasource.driver-class-name =com.mysql.jdbc.Driver
spring.jpa.show-sql: true
i am using sqlyog and wamp server.
gradle.build file:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
}
i am giving all required authentication info correctly, still getting this error.

Related

Failed to initialize JPA EntityManagerFactory: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

My application runs properly in local environment. But in Docker(of AWS EC2) isn't working.
When I docker logs my-spring-image
2021-11-09 11:10:49.793 ERROR 7 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.NoClassDefFoundError: org/locationtech/jts/geom/Geometry
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166) ~[na:na]
at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3191) ~[na:na]
at java.base/java.lang.Class.getMethods(Class.java:1904) ~[na:na]
at org.springframework.data.repository.util.ReactiveWrappers.usesReactiveType(ReactiveWrappers.java:159) ~[spring-data-commons-2.5.5.jar!/:2.5.5]
at org.springframework.data.repository.core.support.AbstractRepositoryMetadata.isReactiveRepository(AbstractRepositoryMetadata.java:160) ~[spring-data-commons-2.5.5.jar!/:2.5.5]
at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.useRepositoryConfiguration(RepositoryConfigurationExtensionSupport.java:366) ~[spring-data-commons-2.5.5.jar!/:2.5.5]
And this is my build.gradle
buildscript {
ext {
queryDslVersion = "4.4.0"
}
}
plugins {
id 'org.springframework.boot' version '2.5.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
// querydsl
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
group = 'ssafy'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// Web
implementation 'org.springframework.boot:spring-boot-starter-web'
// WebFlux
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// MySQL Database
runtimeOnly 'mysql:mysql-connector-java'
//spatial query
compileOnly 'org.hibernate:hibernate-spatial'
// JPA Hibernate
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
// Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'
// java-jwt : https://github.com/auth0/java-jwt
implementation 'com.auth0:java-jwt:3.18.2'
// OAuth
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'
//firebase
implementation 'com.google.firebase:firebase-admin:6.8.1'
// okhttp
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2'
// swagger
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
implementation 'io.springfox:springfox-boot-starter:3.0.0'
// Dev Tools
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// p6spy : https://github.com/gavlyukovskiy/spring-boot-data-source-decorator
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.7.1'
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
// JsonObject 사용
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
//Tymeleaf
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
// s3
implementation('org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE')
//javax
implementation("javax.annotation:javax.annotation-api:1.3.2")
annotationProcessor("javax.annotation:javax.annotation-api:1.3.2")
// querydsl
implementation 'com.querydsl:querydsl-jpa'
}
test {
useJUnitPlatform()
}
// querydsl
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
configurations {
querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
And this is application.yml
spring:
profiles:
include: API-KEY
## MYSQL 일 경우에
datasource:
url: jdbc:mysql://{ip-address}:3306/coffee_station?useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=UTF-8&serverTimezone=UTC
username: username
password: password
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database: mysql
database-platform: org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
default_batch_fetch_size: 500
open-in-view: false
logging.level:
org.hibernate.SQL: debug
decorator:
datasource:
p6spy:
enable-logging: true
jwt:
secret: ---------secret key----------
cloud:
aws:
s3:
bucket: bucket-name
region:
static: ap-northeast-2
stack:
auto: false
And this is my dockerfile
FROM openjdk:11-jdk AS build
WORKDIR /app
COPY gradlew .
COPY gradle gradle
COPY build.gradle .
COPY settings.gradle .
COPY src src
COPY src/main/resources/application.yml src/main/resources/application.yml
COPY src/main/resources/application-API-KEY.properties src/main/resources/application-API-KEY.properties
RUN cat src/main/resources/application.yml
RUN cat src/main/resources/application-API-KEY.properties
RUN chmod +x gradlew
RUN rm -rf build/generated
RUN ["./gradlew", "clean", "build", "--stacktrace", "--exclude-task", "test"]
FROM openjdk:11-jdk
COPY --from=build /app/build/libs/runner-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT java -jar app.jar
and Jenkins always said "Build Success"
I checked application.yml and application-API-KEY.properties create successfully under {APP}/resources, too.
Please help me... :) Thank you
I found my error in build.gradle.
This problem was caused by 'compileOnly'
I changed my build.gradle.
compileOnly 'org.hibernate:hibernate-spatial'
-> implementation 'org.hibernate:hibernate-spatial'
Then it worked properly.

Conflict org.springframework.boot.test.context.SpringBootTest; and org.springframework.test.context.junit.jupiter.SpringExtension;

I'm developing a spring boot app.
In my build.gradle I have added the dependency:
compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
to use MockMultipartFile in my service:
import org.springframework.mock.web.MockMultipartFile;
...
...
MultipartFile multipartFile = new MockMultipartFile("file",
file.getName(), "image/jpeg", IOUtils.toByteArray(input));
But now in the testing class I have this error:
This is my build.gradle:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'mysql:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'
compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.sun.xml.bind:jaxb-core:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'javax.activation:activation:1.1.1'
compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
testCompile('org.mockito:mockito-junit-jupiter:2.23.0')
compile 'org.modelmapper:modelmapper:2.3.0'
compile 'com.google.firebase:firebase-admin:6.13.0'
compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
}
You use a quite old version of Spring Test:
compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
I assume Spring Test 3.1.1 did not yet have the JUnit JUpiter SpringExtension. Either update spring-test to a more recent version or remove it from your build.gradle and let Spring Boot with the Spring Boot Starter Test manage the dependency version of spring-test.
So your updated dependencies section could look like the following:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
// this is your testing swiss-army knife - take a look at its transitive dependency
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'mysql:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'
compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.sun.xml.bind:jaxb-core:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'javax.activation:activation:1.1.1'
compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'
// REMOVE (managed by Spring Boot Starter Test) testCompile 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
// REMOVE (managed by Spring Boot Starter Test) testCompile('org.mockito:mockito-junit-jupiter:2.23.0')
compile 'org.modelmapper:modelmapper:2.3.0'
compile 'com.google.firebase:firebase-admin:6.13.0'
// REMOVE compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'

SQLInvalidAuthorizationSpecException: (conn=63818) Access denied for user 'ravi'#'hostname' (using password: YES)

I am able to connect cloud mysql server if I use hardcoded without externalizing it password=ravi#123 instead of the below, but at the moment I use the below format in order to use the value from the environment variable, it fails in spring boot. A hostname is our azure managed MySQL server host.
I googled enough StackOverflow solutions and tried multiple other options along with character encoding adding to connection string URL still no luck!
characterEncoding=UTF-8
url=jdbc:mysql://${mysql_host:hostname}:${mysql_port:3306}/ravidb?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&autoReconnect=true&allowPublicKeyRetrieval=true
Could anybody help me to understand what I am missing? And what is the possible fix considering I have no option of modifying username or password?
application.yaml
spring:
profiles:
active: development
jackson:
serialization:
fail-on-empty-beans: false
datasource:
driver-class-name: org.mariadb.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mariadb://${mysql_host:hostname}:${mysql_port:3306}/ravidb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&autoReconnect=true&allowPublicKeyRetrieval=true
username: ${mysql_user:ravi#ravidb}
password: ${mysql_password:ravi#123}
hikari:
auto-commit: true
connection-timeout: 20000
idle-timeout: 300000
max-lifetime: 1200000
maximum-pool-size: 12
minimum-idle: 5
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MariaDBDialect
format_sql: true
id:
new_generator_mappings: false
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.9.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.asciidoctor.convert' version '1.5.8'
id 'java'
id 'groovy'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testCompile 'org.spockframework:spock-core:1.3-groovy-2.5'
testCompile 'org.spockframework:spock-spring:1.3-groovy-2.5'
compile 'org.apache.commons:commons-lang3:3.11'
compile 'org.javassist:javassist:3.24.0-GA'
runtime 'mysql:mysql-connector-java'
runtime 'org.mariadb.jdbc:mariadb-java-client:2.7.1'
compile 'junit:junit:4.12'
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
implementation group: 'com.google.guava', name: 'guava', version: '23.0'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
}
I wondered to see it worked if I just change key name mysql_password to mysql_pass
Issue reslved with this change:
spring.datasource.password=${mysql_pass:ravi#123}

Springboot version upgrade - my sql error while deploying in aws elastic beanstalk

We are trying to upgrade our project through build.gradle dependencies :
build.gradle file:
buildscript {
ext {
springBootVersion = '2.3.3.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
group = 'testing'
version = '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "jacoco"
apply from: 'docker.gradle'
sourceCompatibility = 1.8
bootJar {
launchScript()
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
compile ('org.springframework.boot:spring-boot-starter-data-jpa')
compile ('org.springframework.boot:spring-boot-starter-web')
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.flywaydb:flyway-core'
runtime 'mysql:mysql-connector-java:5.1.47'
implementation 'com.zaxxer:HikariCP'
annotationProcessor('org.hibernate:hibernate-jpamodelgen')
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.mobile:spring-mobile-device:1.1.5.RELEASE'
implementation 'io.jsonwebtoken:jjwt-api:0.10.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.10.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.10.5'
implementation 'com.amazonaws:aws-java-sdk-s3:1.11.136'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testCompile('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation('org.springframework.security:spring-security-test')
compile 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.apache.commons:commons-lang3'
implementation 'com.univocity:univocity-parsers:2.7.6'
implementation 'org.quartz-scheduler:quartz:2.2.1'
implementation 'org.apache.poi:poi:3.17'
implementation 'org.apache.poi:poi-ooxml:3.17'
}
test.reports.junitXml.setDestination(file("${buildDir}/test-results"))
jacocoTestReport {
reports {
html.destination file("${buildDir}/jacocoHtml")
}
}
sourceSets {
main {
java {
srcDirs += "src/jpaModelgen/java"
}
}
}
compileJava {
options.compilerArgs += ['-AaddGenerationDate=true'] // Specific to Hibernate JPA meta model generation processor.
options.annotationProcessorGeneratedSourcesDirectory = file("src/jpaModelgen/java")
}
application.properties file:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database=mysql
spring.data.jpa.repositories.enabled=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.url= jdbc:mysql://MyDB:3306/myschema
spring.datasource.username= testing
spring.datasource.password= root
spring-boot from version 1.5.7 to 2.3.3
Gradle from versionGradle-4.8-all to Gradle-6.4.1-all
while we run aplication in localy we get folowing output in log,
o.f.c.internal.database.DatabaseFactory : Database: jdbc:mysql://MyDB:3306/myschema (MySQL 5.7)
when we deploy this same code to AWS Elastic Beanstalk,
We are getting the following error:
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.internal.command.DbMigrate$FlywayMigrateException:
Migration V3__Sequence_Table.sql failed
---------------------------------------
SQL State : 42001
Error Code : 42001
Message : Syntax error in SQL statement "DELIMITER[*]
JDBC connection URL has been changed as below now,
o.f.c.internal.database.DatabaseFactory : Database: jdbc:h2:mem:testdb (H2 1.4)
Is this the cause of the above flyway migration error or Docker version error?
problem:
Run command for jar file is a problem for this project `
Dspring.config.location=run.properties this commad execute only run.properties
solution:
Instead of the above run command, I have tried this run command for the jar file
Dspring.config.additional-location=run.properties
this was working well

Using mongodb and hibernate with grails3

I need to run a Grails 3 app against MySql/Hibernate and MongoDB.
(Had is running on Grails 2.5 without an hitch).
I tried many different combinations, searched and tried related SO answers, but with no luck.
Used the latest Mongodb plugin doc for the configuration.
Using Grails 3.1.10:
grailsVersion=3.1.10
I started with the following details in build.gradle:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2"
classpath "org.grails.plugins:hibernate4:5.0.10"
}
}
...
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
//databases
compile 'org.grails.plugins:mongodb:6.0.0.M2'
runtime 'mysql:mysql-connector-java:5.1.36'
...
}
The application.yml:
---
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
environments:
development:
dataSource:
dbCreate: update
url: jdbc:mysql://localhost:3306/dbname
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username : "xxx"
password : "yyy"
properties:
maxActive : 50
maxIdle: 25
minIdle: 5
...
grails:
mongodb:
host: "localhost"
port: 27017
username: "blah"
password: "blah"
databaseName: "foo"
Now this gives me an error:
15:13:58.001 [QUIET] [system.out] ERROR org.springframework.boot.SpringApplication - Application startup failed
15:13:58.001 [QUIET] [system.out] java.lang.NoClassDefFoundError: org/grails/datastore/gorm/plugin/support/ConfigSupport
15:13:58.001 [QUIET] [system.out] at grails.plugins.mongodb.MongodbGrailsPlugin.doWithSpring(MongodbGrailsPlugin.groovy:42)
The MongoDB grails plugin does not find ConfigSupport
ConfigSupport.prepareConfig(config, (ConfigurableApplicationContext) applicationContext)
I then tried to add the following plugins in all orders possible:
//compile 'org.grails:grails-datastore-gorm-hibernate4:6.0.0.M2'
//compile 'org.grails:grails-datastore-core:4.0.0.M2'
//compile 'org.grails:grails-datastore-gorm-plugin-support:6.0.0.M2'
//compile 'org.springframework.data:spring-data-mongodb:1.9.2.RELEASE'
//compile 'org.mongodb:mongodb-driver:3.3.0'
//compile 'org.mongodb:mongo-java-driver:3.3.0'
No luck.
I also moved the mongodb: section down to the grails: section in the yml file. Same error.
So the question is how to get MongoDB running with MySql with grails3.
Ok, stupid me. I solved the puzzle using these simple dependency settings:
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
//databases
compile 'org.grails.plugins:mongodb'
runtime 'mysql:mysql-connector-java:5.1.36'
runtime 'com.googlecode.json-simple:json-simple:1.1'
It seems that the following line made the difference:
compile 'org.grails.plugins:mongodb'
Omitting the version number. This should be explained in the docs a bit better. Usually it is a good thing defining versions, or is this too old fashioned these days? :-)
Happy to have it working
Ok I found correct previous answer for referring mongodb plugin, i.e. compile 'org.grails.plugins:mongodb' but I want to sum up with a brief checklist, having me a correctly running mixed solution (both hibernate + mysql and mongodb), after many trials and errors. So, in order to have a mixed mysql/mongo grails3 configuration, you have to
insert compile 'org.grails.plugins:mongodb' (without any version) in build.gradle (remember that there is no BuildConfig.groovy in grails 3, as documented here/grails2->3)
keep ordinary dependency to hibernate/mysql, for example: compile 'org.grails.plugins:hibernate4' compile 'org.hibernate:hibernate-ehcache' runtime 'mysql:mysql-connector-java:5.1.38'
set up correctly connections in application.yml, but I prefer old-style application.groovy, in grails-app/conf (as in older GRAILS), as below (remember that in GRAILS3 differently from 2 you have to use mongodb and no more mongo keyword)
use ordinary GRAILS entities for mysql mapping
and use static mapWith="mongo" inside mongo entities (as stated in GRAILS-mongo doc)
not use usual mysql Long id for mongo, but ObjectId id, and for it import org.bson.types.ObjectId
Application.groovy set up
grails {
mongodb {
host = "localhost"
port = 27017
username = mongouser
password= mongopasswd
databaseName = mongoDBname
}
}
environments {
development {
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
username = ...
password = ...
dbCreate = "create"
url = "jdbc:mysql://127.0.0.1:3306/dbnameMysql"
}
}
}
That's all. Enjoy MongoDB.
Not sure I can help much other than show my config that is confirmed working.
I've recently converted a 2.4.4 app to 3.1.8, admittedly I'm using Oracle as my RDBMS rather than mysql.
In build.gradle I just have:
dependencies {
classpath "org.grails.plugins:hibernate4:5.0.6"
...
}
dependencies {
compile "org.grails.plugins:mongodb:5.0.0.RC1"
...
}
And in application.yml:
mongodb:
databaseName: 'myApp'
engine: mapping
The engine: mapping bit was crucial for me, it reverts to the previous persistence engine as described here http://gorm.grails.org/latest/mongodb/manual/index.html
The doWithSpring() closure in my MongodbGrailsPlugin.groovy looks like:
Closure doWithSpring() {
def initializer = new MongoDbDataStoreSpringInitializer(config, grailsApplication.getArtefacts(DomainClassArtefactHandler.TYPE).collect() { GrailsClass cls -> cls.clazz })
initializer.registerApplicationIfNotPresent = false
initializer.setSecondaryDatastore( manager.hasGrailsPlugin("hibernate") )
return initializer.getBeanDefinitions((BeanDefinitionRegistry)applicationContext)
}
No reference to ConfigSupport which may have been added (or not) in your later version or there's a dependency missing.