Error in Launching application with different DB profile defined in the spring config server into client spring boot project - docker

I am trying to develop a microservice and deployment for two different regions. Two different region using two different database. So for using that, I created one spring cloud config server and defined database property for two different profiles,
Here Is my spring cloud config server project details, Created config folder in src/main/resources and add two files,
bootstrap-vcu.properties file containing,
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/milleTech_users
spring.datasource.username=postgres
spring.datasource.password=postgresql
bootstrap-sp.properties file containing,
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/espace
spring.datasource.username=postgres
spring.datasource.password=postgresql
Application.properties containing,
server.port=8888
spring.profiles.active=native
Bootstrap.properties
spring.cloud.config.uri=localhost:8888
Folder structure for config server is as following,
And my pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
And created separate project for spring cloud config client,
Config client project application.properties file is like,
server.port=8080
spring.cloud.config.uri=localhost:8888
And launching client application like ,
java -jar -Dsping.profiles.active=vcu ConfigClient-0.0.1-SNAPSHOT.war
But getting error as
"Failed to auto-configure a DataSource: 'spring.datasource.url' is not
specified and no embedded datasource could be auto-configured"
Reason: Failed to determine a suitable driver class

Try to rename DbVcu.properties into application-DbVcu.properties and move it to src/main/ressources folder.

Related

log4j2 can't locate config file

I'm using log4j2.13.0 with Java 11, and it will not find the XML config file using VM arg -Dlog4j.configurationFile=/path/tofile, despite everything I'm reading saying that should work. It can find it if I cput the file on the classpath, but I'd like to point it to it explicitly.
This is what I'm installing via Maven:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.0</version>
</dependency>
I do not have any slf4j or other logging frameworks installed. Am I missing some additional jar files?

Processor App in Spring Boot 2.2.4/Hoxton.SR1 not working in Spring Cloud Data Flow 2.4.1

I am trying to develop a new application to work on SCDF 2.4.1 and Skipper 2.3.1
I took the samples from
https://github.com/sabbyanandan/stream-programming-models
I built them locally. Downloaded the docker compose for SCDF kafka, set the Versions and mount my repo and start my docker compose.
When I deploy the "function" module and create a simple stream
http | customUpper | log
I see the sample working fine and able to see log output as expected.
When I modify the function stream app, to use Spring Boot, 2.2.4 and Hoxton.SR1 for cloud stream dependencies. I do not see any output in the log.
BootApp
public class FunctionStreamSampleApplication {
public static void main(String[] args) {
SpringApplication.run(FunctionStreamSampleApplication.class, args);
}
#Bean
public Function<String, String> uppercase() {
return data -> {
System.out.println("Input "+data);
return data.toUpperCase();
};
}
}
application.yml
spring:
cloud:
stream:
function:
definition: uppercase
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>function219</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>function219</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I have removed the test classes just to strip it to bare minimum to avoid other dependency. The same app does work when deployed as is using the 2.1.4 version of spring boot it was originally built on. Do let know if there are changes needed to be done to make it work on SCDF
When i use kafkatools to check the topics created by the stream, I see messages only in the streamname.http, but processor doesnt seem to be reading messages as my sysout is not getting printed.
I believe the problem is that the current published stream apps, http and log, use an earlier version of spring-cloud-stream, based on spring boot 2.1.x. The newer version of spring-cloud-stream that is compatible with boot 2.2.x is not backwards compatible. All apps in the stream must be on the same (or compatible) spring-cloud-stream versions. I expect if you look at the log for custom processor, you will see some conversion error.
For function based stream modules to work with SCDF, you need to add the appropriate binding name properties to input and output to your application properties as described here: https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/3.0.3.RELEASE/reference/html/spring-cloud-stream.html#_functional_binding_names
Essentially, this maps the functional binding endpoint names to the SCDF endpoint names, input and output. For example, if you have a Function `foo':
spring.cloud.stream.function.bindings.foo-in-0=input
spring.cloud.stream.function.bindings.foo-out-0=output
.Future releases of the prepackaged stream modules will use the Functional paradigm and will provide these properties automatically.

Monitoring custom Stream apps in Spring Cloud data flow

I am trying scdf and its monitoring with prometheus and grafana. I followed the documentation available and able to deploy the sample stream and able to see the metrics in the grafana.
I have created a stream with some custom stream app (other than the supplied rabbit mq starter apps).
Stream:
htt | participant | log
But am not able see the "participant" application metrics in gafana. But able to see the metrics of http and log apps.
Added below properties in application.properties.
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
spring.cloud.streamapp.security.enabled=false
Added below dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--<!– https://mvnrepository.com/artifact/org.springframework.cloud.stream.app/app-starters-common –>-->
<!--<dependency>-->
<!--<groupId>org.springframework.cloud.stream.app</groupId>-->
<!--<artifactId>app-starters-common</artifactId>-->
<!--<version>2.1.1.RELEASE</version>-->
<!--<type>pom</type>-->
<!--</dependency>-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
After adding app-starters-common:org.springframework.cloud.stream.app dependency localhost:< port >/ opens a login page.
I think you need app-starters-micrometer-common dependency which adds some of the micrometer tags to your app. This dependency is intended to be used by the Spring cloud stream app starters and I believe you can use it in your custom application as well.
I came across this question while looking answers for the same.
Here is my working code snippet:-
Pom.xml
<dependency>
<groupId>org.springframework.cloud.stream.app</groupId>
<artifactId>app-starters-micrometer-common</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-jmx</artifactId>
</dependency>
application property change to enable prometheus and disable security(login page)
management.endpoints.web.exposure.include=*
management.metrics.export.prometheus.enabled=true
-- this one to remove security (login page), which was automatically added by app-starter-micrometre-common dependency.
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration, org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
or
exclude the dependency, I excluded config-client and few other since I don't need them in my application.
<dependency>
<groupId>org.springframework.cloud.stream.app</groupId>
<artifactId>app-starters-micrometer-common</artifactId>
<version>2.1.2.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>spring-security-config</artifactId>
<groupId>org.springframework.security</groupId>
</exclusion>
<exclusion>
<artifactId>spring-cloud-services-starter-config-client</artifactId>
<groupId>io.pivotal.spring.cloud</groupId>
</exclusion>
<exclusion>
<artifactId>*</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
With later Data Flow 2.3.x, you need to add the following dependencies to your processor:
<dependency>
<groupId>org.springframework.cloud.stream.app</groupId>
<artifactId>app-starters-micrometer-common</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer.prometheus</groupId>
<artifactId>prometheus-rsocket-spring</artifactId>
<version>0.9.0</version>
</dependency>
The app-starters-micrometer-common injects DataFlow specific tags, such as stream.name, application.name, application.type all used by the dashboard to aggregate the required metrics.
In addition you can follow instructions in the sample projects, showing how to build custom Source, Processor and Sink apps with enabled prometheus monitoring:
https://github.com/spring-cloud/spring-cloud-dataflow-samples/tree/master/monitoring-samples/stream-apps

What do I need to import to make `SparkConf` resolvable?

I am setting up a Java Spark application and am following the Datastax documentation on getting started with the Java API. I've added
<dependencies>
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector-java_2.10</artifactId>
<version>1.1.1</version>
</dependency>
...
</dependencies>
and (a previously installed dse.jar to my local Maven repository)
<dependency>
<groupId>com.datastax</groupId>
<artifactId>dse</artifactId>
<version>version number</version>
</dependency>
. Next step in the guide is to do
SparkConf conf = DseSparkConfHelper.enrichSparkConf(new SparkConf())
.setAppName( "My application");
DseSparkContext sc = new DseSparkContext(conf);
. However, the class SparkConf can't be resolved. Should it? Am I missing some additional Maven dependency? Which?
The class is org.apache.spark.SparkConf which is in the spark-core_scala version artifact.
So your pom.xml might look like this:
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector-java_2.10</artifactId>
<version>1.5.0-M2</version>
</dependency>
<dependency>
<groupId>com.datastax</groupId>
<artifactId>dse</artifactId>
<version>*version number*</version>
</dependency>
</dependencies>
The spark-core JAR is also located in:
dse_install/resources/spark/lib/spark_core_2.10-version.jar (tarball)
or:
/usr/share/dse/spark/lib/spark_core_2.10-version.jar (package installs)

Building JSF Project with Spring Boot

I want to build a Spring Boot Project with JSF and Maven.
I tried it with the dependency with the artifact-id spring-boot-starter-web.
The Error Message is, that the JSPFacelet is missing.
Know everyone these Problem and have solve it?
Maybe you need specify which artifact is the parent of your POM
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

Resources