Connecting Squirrel Client to Embedded Teiid Server - java

I have a Spring Boot project, on which I have some csv files and have converted them into entities and querying them based on my requirement. For this approach, I am using Teiid Spring Boot Starter, which is starting a embedded server -
This is the console startup log -
Starting embedded database: url='jdbc:teiid:spring;PassthroughAuthentication=true;useCallingThread=true;autoFailover=true;waitForLoad=5000;autoCommitTxn=OFF;disableLocalTxn=true', username='null' ````
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.teiid</groupId>
<artifactId>teiid-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.teiid</groupId>
<artifactId>teiid-12.1.1-jdbc</artifactId>
<version>12.2.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/teiid-12.2.1-jdbc.jar</systemPath>
</dependency>
</dependencies>
application.properties
spring.application.name=Teiid-spring-boot
spring.teiid.model.package=com.example.demo.model
spring.teiid.file.parent-directory=src/main/resources/csv
#######
logging.level.org.teiid.spring=TRACE
spring.main.allow-bean-definition-overriding=true
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
I have Squirrel SQL client setup, have added the driver for Teiid as well.
teiid-12.2.1-jdbc.jar
Squirrel SQL connection settings used -
name - Teiid
example url - jdbc:teiid:spring
website url - http://teiid.org
But while connecting, getting this following error -
teiid: JDBC Driver class not found
class java.lang.ClassNotFoundException: org.jboss.modules.ModuleLoadException

There are multiple issues that need to be fixed.
You do not need the teiid-12.1.1-jdbc dependency in pom.xml
Add teiid.jdbc-enable=true to your application.properties that will open a jdbc port 31000 for the application you built.
Run your application
Then add the Teiid JDBC driver to SquirreL (which you seemed to be already done)
Use the URL as jdbc:teiid:spring#mm://localhost:31000 where localhost is host where you are running your teiid-spring application.

Related

PostgreSQL ‘database does not exist’ - Java Spring Boot, Flyway, Docker/PostgreSQL

I’m following this tutorial: https://www.youtube.com/watch?v=vtPkZShrvXQ
… and I am having trouble with database migrations. I am using Spring Boot 2.2.7, and I have created a PostgreSQL database called “demodb”
When I run the program, the console gives the error:
org.postgresql.util.PSQLException: FATAL: database "demodb" does not exist
Here is my application.yml file, which contains the database info:
app:
datasource:
plaltform: postgres
jdbc-url: jdbc:postgresql://localhost:5432/demodb
username: postgres
password: password
pool-size: 30
Here are my dependencies in the pom.xml file:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.2.7.RELEASE</version>
</dependency>
</dependencies>
I'm running my migrations in a separate fold, and like I said, the database "demodb" DOES exist (I created it from the terminal), so I’m not sure why I’m getting this error. Any ideas?
So I was following along the same tutorial. Then I switched to the same persons video on installing postgres: https://youtu.be/4smnWU0BhrA?t=811
At the time stamp I linked you end up starting postgres in the mac application. Make sure you stop it. The issue for me was that since I started that postgres before the one inside docker, that original postgres was listening on port 5432. And that original postgres did not have demodb.
If that is not the solution try to kill whatever is listening to port 5432, then try again or restart the docker instance.
lsof -i :5432
Get the PID, lets say its 1001, then do:
kill -9 1001
could be related to a typo in your application.yml file...
app:
datasource:
platform: postgres
(your wrote plaltform)
other than that I wonder why you don't use the default Spring Boot properties to configure your database connection:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: dbc:postgresql://localhost:5432/demodb
username: postgres
password: password
please also have a look at this reference of Spring Boot properties: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#data-properties

Spring Boot - Issue with Spring Boot Starter Actuator

So I am creating a new spring boot project and wanted to play around with spring-boot-starter-actuator. However I am facing issues when starting the application.
Pom Snippet:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<spring-boot.version>2.2.0.RELEASE</spring-boot.version>
spring-boots on my classpath:
Error while starting the application:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.actuate.autoconfigure.metrics.orm.jpa.HibernateMetricsAutoConfiguration.bindEntityManagerFactoryToRegistry(HibernateMetricsAutoConfiguration.java:68)
The following method did not exist:
io.micrometer.core.instrument.binder.jpa.HibernateMetrics.<init>(Lorg/hibernate/SessionFactory;Ljava/lang/String;Ljava/lang/Iterable;)V
The method's class, io.micrometer.core.instrument.binder.jpa.HibernateMetrics, is available from the following locations:
jar:file:/C:/Users/rahul/.m2/repository/io/micrometer/micrometer-core/1.0.2/micrometer-core-1.0.2.jar!/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.class
It was loaded from the following location:
file:/C:/Users/rahul/.m2/repository/io/micrometer/micrometer-core/1.0.2/micrometer-core-1.0.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of io.micrometer.core.instrument.binder.jpa.HibernateMetrics
At this point the exception happens:
However there is only one constructor of HibernateMetrics which looks like this:
public HibernateMetrics(EntityManagerFactory entityManagerFactory, String entityManagerFactoryName, Iterable<Tag> tags) {
this.tags = Tags.concat(tags, "entityManagerFactory", entityManagerFactoryName);
this.stats = hasStatisticsEnabled(entityManagerFactory) ? getStatistics(entityManagerFactory) : null;
}
From the dependency analyzer, one could see that there are not multiple versions of micrometer-core:
I also tried with spring-boot-starter-actuator version of 2.2.0.RELEASE but that has the same issue.
I am not sure what am I missing here, any help will be really appreciated.
Assuming that you'll connect a spring-boot-actuator application to a JMX console. ( "because it's not a web application")
I've used Spring Initializr based on your pom dependencies and a CommandLineRunner example. Github example: https://github.com/thiagochagas/actuator-example
Adjusts:
I've removed the "spring-boot-starter" dependency :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
I've used a Thread.sleep(30000L) in the DemoApplication class to simplify the example.
Install and Run the Application:
./mvnw clean install
java -jar target/demo-0.0.1-SNAPSHOT.jar
Open the jconsole:
$JAVA_HOME/bin/jconsole
While your application is running it should be on the jconsole.
Select your "demo-0.0.1-SNAPSHOT.jar" to analyze:
If this message is shown, select the option "Insecure Connection":
Analysis of the running application:

Not able to add JPA dependency into spring-boot project

I am trying to add JPA Maven dependency to already created spring-boot project but I am getting following error:
Error: Could not find or load main class com.kame.demo.DemoApplication
When I remove it the error is gone.
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>8.5.32</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
application.properties
spring.mvc.view.prefix=/pages/
spring.mvc.view.suffix=.jsp
spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:navin
I tried to find answer online but none was solution for me.
Also tried to create > Spring starter project > an there immediately add JPA, Web and H2 but still same error.
I am using STS IDE, is something related to it maybe?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Is itself a demo project with an extending SpringBoot class as the main class of your project. But this dependency does the same :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
So there is high chances that both will clash...
The solution is to import the correct dependency for jpa and not the spring boot starter jpa dependency.
EDIT
This one might do the trick instead :
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
But I recommend you read the official documents to get started properly : https://docs.spring.io/spring-data/jpa/docs/2.1.0.RC2/reference/html/
I faced the same issue while I tried to add JPA dependency manually in POM.xml after creating Spring boot with Web only.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
Root cause of the problem:- JPA dependency jar was missing. verify:-
File->Project structure->Modules->Dependencies and you will not find any jar org.springframework.boot:spring-boot-starter-data-jpa:2.4.3 (I am using spring boot 2.4.3 but in your case version can be different)
Solution:-
Step 1
File -> Invalidate Caches / Restart... and choosing the Invalidate and Restart option fixed the issue. can be a stale cache issue
Step 2
Under IntelliJ Idea open POM.xml right click-> Maven-> Reload project.
Maven will download the JPA dependency jar and will add into the project. Verify if JPA jar is added or not.
Step 3
Selecting File -> Invalidate Caches / Restart... and choosing the Invalidate and Restart option fixed the issue.
NB:- If you are not using ItellIj id then please force Maven to download dependency (for step2)

Spring unknown property 'spring.cloud.config.server'

I am attempting to connect to a git config server in my spring project following the example below in an eclipse IDE
https://cloud.spring.io/spring-cloud-static/Camden.SR5/
However I am running into issues being able to resolve the properties needed as eclipse is not able to recognize the server property in my bootstrap.yml (unknown property 'spring.cloud.config.server')
spring:
cloud:
config:
*server*:
git:
uri: .....config_server.git
I have included all the dependencies listed in the example above (spring-cloud-dependencies, spring-cloud-starter-config, spring-boot-starter-test) however I still receive the error.
Is there limitations as to when this property can be used? Or is there an additional dependency that is needed?
This was added to the question by the OP and has been moved here.
Turns I just needed to add a spring-cloud-starter-config-server dependency. Not sure why it did not get pulled in by by the others but that did the trick.
here is a small example of how we use it using the spring cloud config:
bootstrap.yml
spring:
profiles:
# this will tell spring to pick the correct profile file
active: sheba
# u must specify your application name for it to be found in the git repository!
application:
name: OpscI2aClient
# now we telling our git client where to locate our config files
cloud:
config:
server:
bootstrap: true
git:
# this the full uri to our repository where the config file
# wich its name is ApplicationName-profileName.yml
# are found
uri: https://some.company.git.com/config/config-repo.git
username: someGitUserName
password: thePasswordOfTheGitUser
# clone the whole config repository on startup
the whole files in the repository are cloned!
clone-on-start: true
# this tell spring the name of the local repository directory
# which in this case it shall create a directory called git_local
relatively to where the application started
basedir:
git_local
so, assuming you have a git repo, it must contain a file OpscI2aClient-sheba.yml
this file is just a simple spring boot configuration file, however, should not contain active profile entry.
that is it.
Just to clarify:
Assuming the application named OpscI2aClient have two profiles, dev and prod,
your git configuration repositoty should actually contain, two files:
1. OpscI2aClient-dev.yml
2. OpscI2aClient-prod.yml
Hope this helps.
I am just adding the POM in which you might find some hints as well
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.scm.id>opsc-scm-server</project.scm.id>
<java.version>1.8</java.version>
<slf4j.version>1.7.2</slf4j.version>
<logback.version>1.1.3</logback.version>
<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
First of all, is it just Eclipse doesn't see server and you can run it from command line with no errors?
In case if it's just Eclipse it could be just wrong indention or tabs. Eclipse is not so smart sometimes.
Try to set it all to plain application.properties file.
Try to run it from command line
Also, I think you have to add credentials section for git + encrypted or not.
Here is valid example of YML that works fine in STS Eclipse:
https://github.com/zobarov/spring-cloud/blob/master/edu-springcloud-configserver/src/main/resources/application.yml

Spring boot with Google Cloud SQL

im trying to deploy my spring boot app to Google App Engine Flex Environment and G Cloud MySQL DB.
I'm having issues connecting to the db.
Tried already some variants, but all unsuccessful.
spring-boot-with-google-cloud-datastore-api-fails-to-run
My properties:
spring:
profiles: googlecloud
jpa:
database: MYSQL
show-sql: false
hibernate:
ddl-auto: update
datasource:
url: jdbc:mysql://google/myproject?cloudSqlInstance=XXXX&user=xxx&password=xxx
My pom.xml (the db dependencies only):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
With this configuration, im getting:
Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.SocketFactory
...Error creating repository beans...
java.lang.NoClassDefFoundError: com/mysql/jdbc/SocketFactory
You can read more details about the change from 5x to 6x connector :
https://dev.mysql.com/doc/connector-j/6.0/en/connector-j-api-changes.html
For the NCDF exception, according to this issue :
https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory/issues/18
I think you have to change your dependencies :
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory-connector-j-6</artifactId>
<version>1.0.2</version>
</dependency>

Categories