Spring module in JBoss 7 - spring

I'm trying to set up Spring 3.0.6 libraries as a module in JBoss 7.
I have all of the jars in modules/org/springframework/main along with the following module.xml
<module xmlns:"urn:jboss:module:1.0" name="org.springframework">
<resources>
<resource-root path="org.springframework.beans-3.0.6.RELEASE.jar"/>
...
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.servlet.api"/>
<module name="org.apache.commons.logging"/>
</dependencies>
</module>
I added org.springframework to the Dependencies line in my MANIFEST.MF
When I deploy the app the following exception is thrown while parsing my spring-servlet.xml file (sorry, this is from a system that is not networked)
SAXParseException: ... Cannot find the declaration of element 'beans'
My first thought was that the module is not being used but if I remove org.springframework from my Dependencies line it fails to find org.springframework.web.context.ContextLoaderListener
Everything works fine if I put the jars in WEB-INF/lib instead of using the module.
spring-servlet.xml contains the following schema reference
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
so I put spring-beans-3.0.xsd in the same directory as spring-servlet.xml and modified the xml to
http://www.springframework.org/schema/beans spring-beans-3.0.xsd
but still no luck.
Anybody have an idea of why the class files are found but the xsd files are not?

Just in case the link that was given in the comments goes away, the problem is that
Problem:
The namespace configuration files are in META-INF, but that directory
is not visible (nor is it configurable via
jboss-deployment-structure.xml)
Solution:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<dependencies>
<module name="org.apache.commons.logging"/>
<module name="org.springframework" >
<imports>
<include path="META-INF**"/>
<include path="org**"/>
</imports>
</module>
</dependencies>
</jboss-deployment-structure>

Was facing the exact same issue. Had set up a spring module on JBoss 7 and then when deploying my application, was facing the below warning:
Failed to read schema document
'http://www.springframework.org/schema/beans/spring-beans-3.2.xsd'
I understood the spring context file was unable to access the schema definitions from the spring jars, after reading the link in the comments above. And hence, the application was not getting deployed. But the solution given there did not work for me. But the below code in the jboss-deployment-structure.xml resolved the issue.
Solution
<module name="org.springframework.spring" meta-inf="export" export="true" />
Added meta-inf="export" attribute.

Related

Where do I put module elements in Checkstyle config file?

I've a simple problem, when I run maven checkstyle, and then go to check what are the problem, I have that:
Line is longer than 80 characters (found 98).
Do someone know how to set it more than 80 characters ? I found few things on the internet, but they don't tell where I need to put that:
<module name="LineLength">
<property name="max" value="120"/>
</module>
Do someone have a clue ?
Cordially
In general, you need to put these module configs into a config file such as the following.
Note: Where LineLength goes depends on the Checkstyle version. Checkstyle 8.24 and higher: directly under Checker; Checkstyle < 8.24: under TreeWalker.
Example for Checkstyle 8.23 and earlier:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<!-- FileSetChecks go here ("parent = Checker") -->
<module name="TreeWalker">
<!-- TreeWalker checks go here ("parent = TreeWalker") -->
<module name="LineLength">
<property name="max" value="120" />
<property name="ignorePattern" value="^\s*\*\s*\S+$" />
</module>
</module>
</module>
As mentioned in another answer, you can subsequently tell Maven where your config file is, or you can specify it inline (not recommended). In either case, you will need to obtain a copy of the config file you are using now, and modify it.
In plain old Maven Checkstyle 3.0.0, the config file would be this one. If you specify a Checkstyle version in your Maven config, modify the version number in the URL to match it.
you can configure a custom checkstyle configuration by configuring the maven-checkstyle-plugin (which you obviouisly already use)
you can use custom-checker-config or inline-checker-config

Whats the correct way to allow different jdbc drivers for deployed applications on JBoss / Wildfly?

My setting is the following:
I got an application, which I deploy in /standalone/deployments
The jboss-deployment-structure.xml of my deployment in /standalone/deployments looks the following:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
[...]
<module name="org.postgresql"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
To drop the jboss-deployment-structure.xml completely (because it must not be used if there are no classloading issues), doesn't work. I use more dependencies (keycloak) beside the driver, which can't be found then.
My module.xml in my module org/postgresql/main looks like this (like described in https://www.keycloak.org/docs/4.8/server_installation/index.html#package-the-jdbc-driver)
<?xml version="1.0" encoding="UTF-8"?>
<module name="org.postgresql" xmlns="urn:jboss:module:1.5">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
My requirement is, to allow different types of jdbc-drivers, e.g. postgres, oracle, mssql.
First option:
I can change my jboss-deployment-structure.xml to
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
[...]
<module name="org.postgresql" optional="TRUE"/>
<module name="com.oracle.ojdbc6" optional="TRUE"/>
[...]
</dependencies>
</deployment>
</jboss-deployment-structure>
(added the optional-parameter)
Then I have to allow all drivers explicitly. Seems to be not the best way.
The idea comes from the standard documentation.
Second option:
I change my module-path to driver/jdbc/main (instead of org/postgres/main) and the module.xml to
<module name="driver.jdbc" xmlns="urn:jboss:module:1.5">
[...]
</module>
(changed name of module)
and go with the module-reference in my jboss-deployment-structure.xml like
<jboss-deployment-structure>
[...]
<module name="driver.jdbc"/>
[...]
</jboss-deployment-structure>
Now I force my customers to name the driver-module like I proposed. They can't name the module like mentioned in every standard-documentation.
The idea comes from this question.
I am doing this in context of a keycloak installation with a self-implemented User-federation to access a separate (legacy) user-database. Therefore dropping the jboss-deployment-structure.xml is no option as mentioned above.
Whats the correct way to achieve my goal of being flexible with the jdbc-driver?
EDIT: mentioned, dropping jboss-deployment-structure.xml is not working.
Keycloak have a very well designed container. You can get inspiration from it for your deployment. Just take a look at how the Dockerfile installs database driver modules and later how to activate those modules using jboss_cli.
Of course, if you can, maybe you can use the container instead. Just make sure to include the module.xml for your driver and activate it on start-up by providing your own entrypoint.
I would suggest you should install all database drivers individually as modules. Individual modules will help you to track and upgrade driver jars easily in the future.
As long as you don't have any classloading problems with your application you don't need to mention these drivers in the jboss-deployment-structure.xml file. They are static modules and will be loaded on server startup.
Moreover, after installing the driver modules, you have to add entries in the standalone.xml file. For example, if I have installed Oracle driver then
<driver name="oracle" module="com.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>
within the tag.
Add a datasource definition within the tag (next to ExampleDS):
<datasource jndi-name="java:/[NAME]" pool-name="OracleDS" enabled="true">
<connection-url>jdbc:oracle:thin:#[HOST_NAME]:1521:[SID]</connection-url>
<driver>oracle[has to match the driver name]</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>5</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>[USER]</user-name>
<password>[PWD]</password>
</security>
</datasource>
At least I went with a hybrid solution of my two above mentioned approaches for the jboss-deployment-structure.xml like as follows
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.postgresql" optional="TRUE"/>
<module name="com.oracle.ojdbc6" optional="TRUE"/>
[...]
<module name="driver.jdbc" optional="TRUE"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
I listed all the relevant database divers as optional modules and listed another one with flexible naming if a driver is desired, which is not mentioned in the list above.

Unable to write application logs using externalized Log4j2 XML configuration using Red Hat EAP 7.1.5

I have an application made of Spring Boot WAR packages that need to be migrated to Red Hat EAP 7.1.5.
In my current setup I do the following:
Each WAR has a dedicated log4j2 XML per environment.
This XML file name is defined in the web.xml
The folder containing the log4j2_xxxx.xml is added to the classpath in the JVM startup script.
The WARs are distributed across multiple run-time instances, with a possibility of one run-time hosting more than one WAR.
I would like to replicate the same using EAP. I do see the external log4j2 XML configuration being successfully loaded, however do not see any log statements being written at all.
I am using the following dependencies for packaging log4j2
org.springframework.boot.spring-boot-starter-log4j2 (version 1.5.7)
org.apache.logging.log4j.log4j-web (version 2.10.0)
I have tried the following:
Define a custom module under $JBOSS_HOME/modules/
Add the log4j2 XML in the same folder.
Refer this as global-module in standalone.xml
When I deploy a WAR I can see that the expected log file is created, which means the log4j2 XML configuration is being read successfully. However no logs get written at all in the application log file.
I have tried to get past this by defining a jboss-deployment-structure XML as follows:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.jboss.log4j.logmanager" />
<module name="org.jboss.logging" />
<module name="org.jboss.logging.commons.logging" />
<module name="org.jboss.logging.jul-to-slf4j-stub" />
</exclusions>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
This results in the application logging being removed from the default JBOSS log (server.log) altogether but it does not write the logs to the designated log as well.
I would expect all the logging being done within the application to be written into the file defined by the external log4j2 XML configuration. Any idea what I am missing?

Wildfly Failed to Load Module for Oracle Driver

I'm attempting to add an Oracle DB datasource to Wildfly 10. Here's what I have:
<wildfly-home>\modules\com\oracle\ojdbc6\main\
module.xml
ojdbc6.jar
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:Wildfly:module:1.0" name="com.oracle.ojdbc6">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.resource.api"/>
<module name="javax.transaction.api"/> <!-- See * below -->
</dependencies>
</module>
* I have tried both with and without the line <module name="javax.transaction.api/>. Some examples I've found online include it. Some do not. It seems to make no difference with whether the error occurs or not.
ojdbc6.jar was copied from <oracle-home>\jdbc\lib\ojdbc6.jar.
I have modified <wildfly-home>\standalone\configuration\standalone.xml to include this within the <drivers> tag:
<driver name="oraclethin" module="com.oracle.ojdbc6">
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
This error message is being spat out when I cd into <wildfly-home>\bin and run .\standalone.bat:
15:17:13,415 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "oraclethin")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.oracle.ojdbc6]"
I've triple checked the spelling on everything. I've tried taking out some lines (and putting them back when nothing changes). Is anyone seeing what I'm missing?
Use xmlns="urn:jboss:module:1.0"
As described in https://docs.jboss.org/author/display/MODULES/Module+descriptors
what solve the issue for me was to enlarge the timeout connection on the standalone.xml file on jboss
<system-properties>
...
<property name="jboss.as.management.blocking.timeout" value="6000"/>
</system-properties>

Issue configuring JBoss EAP 6.1 with hibernate 3.6

I'm trying to deploy an EAR file in my local server but it seems it's still trying to use hibernate 4 (the default option, I guess).
What I have already done:
I've added a hibernate 3 module in $JBOSS_HOME$\modules\org.hibernate\3 with this module.xml file:
<module xmlns="urn:jboss:module:1.0" name="org.hibernate" slot="3">
<resources>
<resource-root path="hibernate3.jar"/>
<resource-root path="commons-collections-3.1.jar"/>
<resource-root path="jta-1.1.jar"/>
<resource-root path="javassist-3.12.0.GA.jar"/>
<resource-root path="antlr-2.7.6.jar"/>
<resource-root path="slf4j-api-1.6.1.jar"/>
<resource-root path="dom4j-1.6.1.jar"/>
<!-- Insert other Hibernate 3 jars to be used here -->
</resources>
<dependencies>
<module name="org.jboss.as.jpa.hibernate" slot="3"/>
<module name="asm.asm"/>
<module name="javax.api"/>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="com.ibm.db2" />
<module name="org.infinispan"/>
</dependencies>
</module>
I've created the data source in standalone-full-ha.xml:
<datasource jndi-name="java:jboss/datasources/txdb" pool-name="txdbDS" enabled="true" use-java-context="true">
<connection-url>jdbc:db2://156.24.30.103:50000/TX_LSPDB</connection-url>
<driver>DB2Driver</driver>
<security>
<user-name> .... </user-name>
<password> .... </password>
</security>
</datasource>
My persistence.xml file has the following entry:
<persistence-unit name="esdb">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/txdb</jta-data-source>
<class>com.gtech.commerce.UidBlockPool</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
<property name="jboss.as.jpa.providerModule" value="org.jboss.as.jpa.hibernate:3" />
</properties>
</persistence-unit>
And this is what I get when I try to deploy:
Caused by: java.lang.ClassCastException: org.springframework.orm.hibernate3.LocalJtaDataSourceConnectionProvider incompatible with org.hibernate.service.jdbc.connections.spi.ConnectionProvider at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:189) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] ... 107 more
Any idea about what I am missing?
UPDATE: I haven't found a solution, so I did the obvious workaround: I am using hibernate 3 bundled with the application, ignoring any module
Imho the problem comes from the fact that the jboss datasource built-in connection pool rely on the default persistence implementation provided with the server.
you can try to override the server datasource configuration
see https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_BRMS_Platform/5/html/BRMS_Administrator_Guide/Configuring_a_Datasource_for_JBoss_Enterprise_Application_Platform_6.html
But i don't know if you can specify the connection pool provider.
You could try otherwise to set up a custom datasource
see http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch01.html
please consider than you won't be any more in this case: JDBC connections obtained from a JNDI datasource automatically participate in the container-managed transactions of the application server.
and will have to properly configure the transaction factory.
As a more general comment I'll advise not to override provided implementation when using a Java EE application server.
If you wan't to use hibernate 3 switch to Jboss 6.0 or do not rely on the built-in java EE container features (and in this case switch to something lighter like jetty or tomcat)

Resources