I would like to just use GitLab CI to run test only not to deploy my app. I manage to assembly this .yml file:
image: java:8
stages:
- build
- test
build:
stage: build
script: ./gradlew build
artifacts:
paths:
- build/libs/myApp-4.0.0-SNAPSHOT.jar
unitTests:
stage: test
script:
- ./gradlew test
And in the GitLab Pipeline I get the following error:
ar.com.sebasira.myApp.myAppApplicationTests > contextLoads FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException
I'm guessing this could be related to database, right? I need to provide that database with credentials in my Server where the runner is?
If so, how should I do it? I'currently using application.properties file to define the connection to the DB.
And one more question... in the .gitlab-ci.yml file I need to put the path to the .jar but that filename will change everytime I update the version of my app. Do I need to manually change it?
As you are starting the whole Spring context with this test (I think it's the generated standard test from Spring Boot) with the annotations #RunWith(SpringRunner.class) and #SpringBootTest you have to provide a datasource. You can do one of the following:
Specify the database credentials in your application.properties in src/test/resources (you could provide a test database on your database server as I wouldn't connect to your production database on every test)
Use an embedded H2 for this test
Use https://www.testcontainers.org/ to provide a real and fresh database for your Spring application test
Regarding your GitlabCI question: Just use * to match any .jar no matter which version: - build/libs/myApp-*.jar
Related
I have a problem about running auth service.
Even if I couldn't determine whether it works, I couldn't run it.
I got the error appearing on the console shown below.
java.lang.IllegalStateException: Unable to load config data from 'configserver:http://localhost:9296'
Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader. If the location is meant to reference a directory, it must end in '/' or File.separator
To run the example
1 ) Run Registry Service
2 ) Run config service
3 ) Run API Gateway
4 ) Run other services
Here is the project link : Project Link
Here is the solution.
After I changed the Spring version of auth which is the same as others, the issue disappeared.
Changed
<version>2.7.5</version>
to
<version>2.7.4</version>
in pom.xml
I'm trying to learn Quarkus, but after adding a JPA dependency the app doesn't initialize anymore.
This is the added dependency:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
Following are the errors I'm having:
[org.tes.uti.TestcontainersConfiguration] (build-47) Attempted to read Testcontainers configuration file at file:/home/fhb/.testcontainers.properties but the file was not found. Exception message: FileNotFoundException: /home/fhb/.testcontainers.properties (No such file or directory)
After that Quarkus keeps on and gets the following error:
Caused by: java.lang.RuntimeException: io.quarkus.runtime.configuration.ConfigurationException: Model classes are defined for the default persistence unit <default> but configured datasource <default> not found: the default EntityManagerFactory will not be created. To solve this, configure the default datasource. Refer to https://quarkus.io/guides/datasource for guidance.
This is my application.properties file:
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=postgres
quarkus.datasource.password=admin
quarkus.datasource..jdbc.url=jdbc:postgresql://localhost:5432/quarkus-social
quarkus.datasource.jdbc.max-size=16
I think that Quarkus is trying to run tests and for that it needs the .testcontainers.properties file, which I've never created. Anyways I don't want to create that file in /home/fhb/, so theres a way to specify that file location?
Besides thatI would like to know if Testcontainers has something to do with unit tests, which I would like to add to my quarkus application.
Thanks in advance for your help.
I guess the problem is a small typo.
Change from
quarkus.datasource..jdbc.url=jdbc:postgresql://localhost:5432/quarkus-social
To
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/quarkus-social
If you don't specify the URL of the database and run in dev or test mode, Quarkus uses test containers to start one database for you.
There are tutorials on quarkus.io/guides/datasource.
About tests, you can use test containers or one in memory database as H2. You can find all this on Quarkus guides.
When The Program is Ran in the Local PC, it is working fine, but if it is running in the docker throws the following error:
Exception in thread "Thread-16" java.lang.NoClassDefFoundError: org/apache/kafka/common/serialization/Serializer
at org.eclipse.kura.example.configurable.ConfigurableExample$1.run(ConfigurableExample.java:52)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.serialization.Serializer cannot be found by org.eclipse.kura.example.configurable_1.0.0.202201251713
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
But this is working fine in the LocalMachine.
What is the issue ?
This may be debugged in following ways:
Ensure that you have all the required dependencies inside your docker container. You may want to check your docker base image first.
Check if you have set the classpath appropriately to include that jar file (kafka-clients).
Validate your entrypoint/cmd which you use to start the service to check if it has the appropriate classpath.
Check your classloader and see why it is not able to load that class.
If your executable is a fat jar file, check if that jar file contains the kafka-clients library where that class is present.
I am newbie with Springboot .I am unable to make jar file of Springboot with Mysql to deploy in AWS using Eclipse IDE.
I create an application which work perfectly fine in Localhost and when i want to deploy it into the AWS I comment all my application.properties file which has code like
#spring.jpa.hibernate.ddl-auto=update
#spring.datasource.url=jdbc:mysql://localhost:3306/db_digitalprofile?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.username=root
#spring.datasource.password=
#server.port=9090
#spring.jpa.show-sql = true
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
and make a new file named as application-prod.properties in src/main/resource with the code:
server.port=5000
spring.datasource.url=jdbc:mysql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.username=${RDS_USERNAME}
spring.datasource.password=${RDS_PASSWORD}
spring.jpa.hibernate.ddl-auto=update
Now when i want to make a jar file from right click on project> Run As>Maven install to create a jar file it throw a error like:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
java.lang.IllegalStateException: Failed to load ApplicationContext
I had also add following dependency in pom.xml
<configuration>
<finalName> digitalProfile</finalName>
</configuration>
Failed to determine a suitable driver class
You need to check the dependencies. No driver found meaning, driver jar is missing which will be used to connect to Database. mysql driver should be present in your pom file or whatever your build file is.
Add this on your application.properties and it should fix your issue.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
I build my spring boot application to .jar file with:
./gradlew build
and when I want to run this app:
java -jar /build/libs/app.jar
I get error:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.data.mongodb.host' in string value "${spring.data.mongodb.host}"
etc.
When I run this app in IntelliJ everything is ok.
My application.properties
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.username=newsAdminUser
spring.data.mongodb.password=abc123
spring.data.mongodb.database=newssystemservice
server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain
What's the problem?