0

I am trying to configure datasources on a Tomcat using Cargo to allow people doing local tests of the software. When I start the application using cargo, I have the following error:

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 cargo maven plugin is configured in this way:

      <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>

The context.xml I provide contains:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/">
    <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>

    <ResourceLink global="jdbc/app" name="jdbc/app" type="javax.sql.DataSource" />

</Context>

and the logic-datasource.xml mentioned in the exception contains:

<?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>

I didn't find a way to debug what's happening by myself.
Do you know what is wrong looking at the configuration or how can I check what cargo is doing? Thanks

Sixro
  • 402
  • 4
  • 16

0 Answers0