How to configure custom main class using YAML in wildfly swarm application - configuration

I am trying to build a Wildfly Swarm application using custom main class specified in plugin configuration ( as shown below )
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>2018.3.3</version>
<configuration>
<mainClass>rnd.web.service.rest.App</mainClass>
</configuration>
</plugin>
But during build/run is show deprecation warning/information (see below) with reference to documentation. But the documentation does not provide any details on how to implement it.
Custom main() usage is intended to be deprecated in a future release
and is no longer supported, please refer to
http://docs.wildfly-swarm.io for YAML configuration that replaces it.
If someone has encountered and implemented it. Please share the approach and correct reference.

As the deprecation warning says, it's not the <mainClass> setting that's deprecated, it's the entire usage of custom main method. All the configuration you do in your main method, you should be able to do with the YAML configuration. If you find something missing, then that's a bug.

Related

Can log4jdbc be used with spring boot?

I have a Spring boot app I'm trying to add database logging to which is better than
spring.jpa.properties.hibernate.show_sql=true
log4jdbc, from
https://github.com/marcosemiao/log4jdbc
seems to be the most up to date fork around, seems to format nicely, fills in parameters and adds timing, exactly what I want.
But when I configure it as stated in the readme, changing
spring.datasource.url=jdbc:mysql://localhost:3306/coindatabase?useSSL=false
to
spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/coindatabase?useSSL=false
something seems to not like my reference to mysql and seems to try to fall back to H2:
Caused by: java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc:log4jdbc:mysql://localhost:3306/coindatabase?useSSL=false
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)
Is there some easy way to make this work together?
log4jdbc for spring boot wrapper:
<groupId>com.integralblue</groupId>
<artifactId>log4jdbc-spring-boot-starter</artifactId>
which seems to pull in the implementation from:
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
Additional info:
Don't modify the spring.datasource.url property in your Spring Boot application.properties file; leave the URL as previously defined to access your MYSQL instance.
Instead, after grabbing the com.integralblue maven target, simply set the logging level of choice (ex logging.level.jdbc.sqltiming=info) and your previously defined log4j log will have the DB stuff in it.
See here as was well
You need to use this library in your build.gradle:
// https://mvnrepository.com/artifact/com.integralblue/log4jdbc-spring-boot-starter
compile group: 'com.integralblue', name: 'log4jdbc-spring-boot-starter', version: '2.0.0'
If you get the warning:
"Loading class 'com.mysql.jdbc.Driver'. This is deprecated. The new driver class is 'com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary."
you can set the correct Driver yourself via properties:
log4jdbc.drivers=com.mysql.cj.jdbc.Driver
log4jdbc.auto.load.popular.drivers=false
The documentation for configuration can be found on Github

wildfly10 and slf4j and logback do not work

I followed the following configuration for wildfly10:
https://developer.jboss.org/thread/237094
So to be able to use slf4j and logback in my application I disabled the logging subsystem:
<jboss-deployment-structure>
<deployment>
<!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
<!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</jboss-deployment-structure>
With this configuration my application uses correctly my logback configuration: the problem is that the server does not use anymore its own logging, so the general information are not written anymore to server.log, but they are written to my application appender.
This sounds very strange to me: I tried a lot of other configurations like excluding directly the modules (i.e. org.slf4j and org.slf4j.impl) on my jboss-deployment-structure.xml file but with no effect.

Unable to Configure CAS Database Authentication

Following this tutorial I am unable to configure database configuration.
Using the cas-overlay, I've added settings to the cas.properties file, but when I run the project it fails to authenticate.
I don't think the settings are loading completely, because my cas.authn.jdbc.query[0].passwordEncoder.type=BCRYPT setting doesn't take.
I'm coming to this pretty green, so I feel like there is a gap in the documentation.
I figured out my problem. It wasn't necessarily the cas.properties file was wrong. I was actually missing a dependency that imports JDBC support.
Their documentation kind of reads like it is supported, but makes an assumption the reader knows to add the dependency.
Added this to my overlay pom.xml
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-support-jdbc</artifactId>
<version>${cas.version}</version>
</dependency>

caused by:java.lang.NoClassDefRoundError:com/mchange/v2/ser/indirector

When I try to use c3p0 to test a mysql database connection, Eclipse shows the following error:
caused by:java.lang.NoClassDefFoundError:com/mchange/v2/ser/indirector,
I googled and was unable to find an answer.
Could anyone help me? I am a java rookie, thanks!
First, make sure that your project is properly loading mchange-commons-java, where the stuff you are com.mchange.v2.ser.* lives. It is a transitive dependency of c3p0.
Hopefully you are using c3p0-0.9.5. Try changing the c3p0 config param contextClassLoaderSource to library to avoid some ClassLoader confusions.
I think you are only placing c3p0 jar in tomcat lib.
If you copy mchange-commons-java jar also than this issue will be resolved.
I have the same problem. And I am using IntelliJ IDEA. Perhaps you can fix it by follow steps:
Add c3p0 and mchange-commons-java to your 'libs' folder and add them
as 'Library';
Open 'File->Project Structure->Project
Settings->Artifacts', then find c3p0-* and mchange-commons-java in
the 'Available Elements', and 'Extract Into Output Root'.
Then
build artifacts again.
In my case I was missing mchange-commons-java-0.2.11 (use your version) jar that contained the com/mchange/v2/ser/indirector class. We need this and c3p0-0.9.5.2 jars to be kept in app/WEB-INF/lib directory.
Just adding that worked!!!

Akka configuration overwritting

I'm trying to overwrite Akka configuration in my application. I have created additional lib for the application, which also has application.conf file as it uses Akka. So I have 2 of them:
application.conf in my lib:
my-conf {
something = 1
}
application.conf in my app, which uses the lib:
something-else = "foo"
my-conf {
something = 1000
}
When I'm running the app from Intellij Idea, everything is fine, and lib configuration is being overwritten. To load the config in my app I'm using simple ConfigFactory.load() operation.
But when I create a jar of my app with mvn clean compile assembly:single and try to run it with this command: java -Xmx4048m -XX:MaxPermSize=512M -Xss256K -classpath myApp.jar com.myapp.example.MyMain I get error:
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'something-else'
So I decided to rename the conf file in my app, and load it in such way:
val defConfig = ConfigFactory load
val myConfig = ConfigFactory load "myconf"
val combined = myConfig.withFallback(defConfig)
val config = ConfigFactory load combined
It finds missing settings, but unfortunately config from my app doesn't override config in my lib.
In my lib I load config in default way: val settings = ConfigFactory load
Also, "my-conf.something" is an important setting, and I'd like to overwrite it from my app.
What I'm doing wrong? Thanks in advance!
Also, I thought there could be an issue how I create the jar:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.myapp.example.MyMain</mainClass>
</manifest>
</archive>
<finalName>loadtest</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>dist-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
Straight from akka documentation:
If you are using Maven to package your application, you can also make use of the Apache Maven Shade Plugin support for Resource Transformers to merge all the reference.confs on the build classpath into one.
This resolved the issue for me.
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>akka.Main</Main-Class>
</manifestEntries>
</transformer>
</transformers>
As far as I understand, your library should create file called reference.conf. According to https://github.com/typesafehub/config :
libraries should use a Config instance provided by the app, if any,
and use ConfigFactory.load() if no special Config is provided.
Libraries should put their defaults in a reference.conf on the
classpath.
So, i suggest putting a reference.conf into your library first, to make it clear that it is default configuration, and you won't need to have a withFallback - typesafe-config will handle it for you.
Update: I don't remember how maven-assembly-plugin works - it may combine all of jar files and resources in a single file, meaning that lib/src/main/resources/application.conf will be overwritten by app/src/main/resources/application.conf in your case - so yet another reason to use reference.conf.
That's right! Just in order to add a bit more information related to that reference.conf I would say that you should go to:
Akka Documentation: http://akka.io/docs/?_ga=1.90177882.150089464.1402497958
, pick the version you are using and in it look for General->Configuration
inside that page look for 'Listing of the Reference Configuration', that's all the content you may need for that reference.conf. In my case I just copied it all.
Hope it helps to save sometime!