cargo-maven3-plugin: unable to add a datasource on tomcat...

100 views
Skip to first unread message

Roberto Simoni

unread,
Jan 11, 2023, 12:29:31 PM1/11/23
to Codehaus Cargo
Hi, I don't know if it is appreciated the cross posting, but I posted a question on Stackoverflow. Then I realised that another similar question was posted before. So I searched how to get support and found this group.
Basically, I tried to configure a datasource using this configuration:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven3-plugin</artifactId>
    <version>1.10.4</version>
    <configuration>
        <container>
            <containerId>tomcat7x</containerId>
            <zipUrlInstaller>
                <url>https://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat/7.0.55/tomcat-7.0.55.zip</url>
            </zipUrlInstaller>
            <timeout>600000</timeout>
            <output>${project.build.directory}/tomcat7x/container.log</output>
            <append>false</append>
            <log>${project.build.directory}/tomcat7x/cargo.log</log>
            <dependencies>
                [...] some dependencies like mysql, etc...
            </dependencies>
        </container>
        <configuration>
            <type>standalone</type>
            <home>${project.build.directory}/tomcat7x/catalina-base</home>
            <properties>
                <cargo.jvmargs>-Xmx4096m</cargo.jvmargs>
                <cargo.datasource.datasource.mysql>
                    cargo.datasource.driver=com.mysql.jdbc.Driver|
                    cargo.datasource.url=jdbc:mysql://server:3306/app|
                    cargo.datasource.jndi=jdbc/app|
                    cargo.datasource.username=ignore|
                    cargo.datasource.password=ignore
                </cargo.datasource.datasource.mysql>
            </properties>
            <configfiles>
                <configfile>
                    <file>${project.basedir}/src/test/resources/tomcat7/tomcat-users.xml</file>
                    <todir>conf</todir>
                </configfile>
                <configfile>
                    <file>${project.basedir}/src/test/resources/tomcat7/context.xml</file>
                    <todir>conf</todir>
                </configfile>
            </configfiles>
        </configuration>
    </configuration>
</plugin>


but when I run cargo I obtained a:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mosesEntityManagerFactory' defined in class path resource [app-logic.xml]: Cannot resolve reference to bean 'appDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appDataSource' defined in class path resource [logic-datasource.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/app] is not bound in this Context. Unable to find [jdbc]. at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334) ...

The content of that file logic-datasource.xml mentioned in the exception is:
<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 
  <bean id="appDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/app" />
  </bean>
 
</beans>


So the problem seems to be that the datasource is not added to the jndi OR that I am not referring to it in the right way. Unfortunately I am unable to understand what's happening.
Do you know what I am doing wrong or something I can do in cargo to debug what's happening?
Thanks
Regards
  R

P.S. the reason I am using such older versions is because I am inherited a very legacy project that didn't even compile anymore since yesterday

S. Ali Tokmen

unread,
Jan 11, 2023, 5:58:51 PM1/11/23
to codehau...@googlegroups.com

Hi Roberto

This is for sure a good place to ask such questions!

As per https://stackoverflow.com/questions/19431517/how-to-retrieve-jndi-using-spring-configuration-instead-of-xml-configuration the java:comp/env/jdbc/app seems unnecessary - Have you tried to simply use jdbc/app?

As for your second question: hints on debugging are explained on https://codehaus-cargo.github.io/cargo/Debugging.html

Regards

S. Ali Tokmen
https://ali.tokmen.com/
https://contact.ali.tokmen.com/
--
You received this message because you are subscribed to the Google Groups "Codehaus Cargo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codehaus-carg...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codehaus-cargo/4c844eb5-00c3-4358-9969-07a5d284aa89n%40googlegroups.com.

Roberto Simoni

unread,
Jan 12, 2023, 2:50:46 AM1/12/23
to Codehaus Cargo
Thanks Ali. I am going to check todai! :)
Regards
  R

Roberto Simoni

unread,
Jan 12, 2023, 6:31:03 AM1/12/23
to Codehaus Cargo
Hi Ali, unfortunately I have not been able to fix the issue.
Even changing the jndiName didn't work.
The problem I think is that configuring datasources (as I did) does not create a real Jndi resource in Tomcat. There is something else missing.

But in the end I have been able to make it work. I leave it here for other people in need of this.
I just used a trick:
  1. I run cargo-maven3-plugin as usual
  2. I took the server.xml generated by cargo (I configured a home so that I can access to all generated files) and copied it to a local folder in my project (I chose src/test/resources/tomcat7)
  3. I added the datasources under the <GlobalNamingResources>
  4. I configured cargo to override the server.xml with my new file
It worked perfectly.
Thanks for the support anyway
  R

S. Ali Tokmen

unread,
Jan 12, 2023, 2:26:09 PM1/12/23
to codehau...@googlegroups.com

Hi Roberto

Good catch!

As per https://tomcat.apache.org/tomcat-7.0-doc/config/globalresources.html#Resource_Definitions, the "cleaner" way is to have the associated <resource-ref> defined in your /WEB-INF/web.xml.

Reply all
Reply to author
Forward
0 new messages