Error when deploying project with additional datasource and modules

I got the following error trace when deploying project to tomcat.


017-10-18 10:20:56.808 WARN  [localhost-startStop-1] com.haulmont.cuba.core.sys.CubaCoreApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Cannot resolve reference to bean 'cubaDataSource_VehicleMaster' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/VehicleMaster] is not bound in this Context. Unable to find [jdbc].
2017-10-18 10:20:56.816 ERROR [localhost-startStop-1] com.haulmont.cuba.core.sys.AbstractWebAppContextLoader - Error initializing application
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Cannot resolve reference to bean 'cubaDataSource_VehicleMaster' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/VehicleMaster] is not bound in this Context. Unable to find [jdbc].
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/VehicleMaster] is not bound in this Context. Unable to find [jdbc].
18-Oct-2017 10:20:56.834 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/heavy-core] startup failed due to previous errors
10:21:00,924 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.docx4j.utils.ResourceUtils] to ERROR
10:21:00,924 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.docx4j.Docx4jProperties] to ERROR
10:21:00,924 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [ org.xlsx4j.jaxb.Context] to ERROR
10:25:17,327 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.docx4j.utils.ResourceUtils] to ERROR
10:25:17,327 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.docx4j.Docx4jProperties] to ERROR
10:25:17,328 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [ org.xlsx4j.jaxb.Context] to ERROR
2017-10-18 10:25:22.875 WARN  [localhost-startStop-1] com.haulmont.cuba.core.sys.CubaCoreApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Cannot resolve reference to bean 'cubaDataSource_VehicleMaster' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/VehicleMaster] is not bound in this Context. Unable to find [jdbc].
2017-10-18 10:25:22.883 ERROR [localhost-startStop-1] com.haulmont.cuba.core.sys.AbstractWebAppContextLoader - Error initializing application
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Cannot resolve reference to bean 'cubaDataSource_VehicleMaster' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/VehicleMaster] is not bound in this Context. Unable to find [jdbc].
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_VehicleMaster' defined in class path resource [no/sws/heavytransport/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/VehicleMaster] is not bound in this Context. Unable to find [jdbc].
18-Oct-2017 10:25:22.897 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/heavy-core] startup failed due to previous errors
10:25:26,944 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.docx4j.utils.ResourceUtils] to ERROR
10:25:26,944 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.docx4j.Docx4jProperties] to ERROR
10:25:26,944 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [ org.xlsx4j.jaxb.Context] to ERROR
10:25:40,214 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.docx4j.utils.ResourceUtils] to ERROR
10:25:40,214 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.docx4j.Docx4jProperties] to ERROR
10:25:40,214 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [ org.xlsx4j.jaxb.Context] to ERROR
2017-10-18 10:35:27.725 ERROR [http-nio-8080-exec-7] com.haulmont.cuba.web.AppUI - Unable to init ui
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)

The project consist of modules and one of the modules is using additional datasource.
When i ran the project in Cuba Studio everything worked as expected.

Here is the setup in the app.settings for main project


cuba.additionalStores = VehicleMaster
cuba.persistenceConfig_MasterVehicle = +no/sws/heavytransport/VehicleMaster-persistence.xml
cuba.dbmsType_MasterVehicle = postgres
cuba.dataSourceJndiName_MasterVehicle = jdbc/VehicleMaster

How do you deploy the app? As a WAR file? If so, could you check the contents of context.xml file inside the WAR? Also, look at tomcat/conf/Catalina/localhost folder - if it has <app_name>.xml file, it overrides context.xml of the respective app.

I deploy as WAR file.

I have now removed all additional data stores and created them again. I have testet the first module Vehicle. It works as intended.
Then I created the App Component descriptor and have built a component.
When I added this component to my Rental module I got this error:


[20:27:20.103] Loading sources for no.sws.vehicle:vehicle-global:0.3-SNAPSHOT
[20:27:21.535] Loading sources for no.sws.vehicle:vehicle-core:0.3-SNAPSHOT
[20:27:24.000] Loading sources for no.sws.vehicle:vehicle-web:0.3-SNAPSHOT
[20:27:26.063] Exception has been thrown by com.haulmont.studio.backend.e.y@5c8a748f:
[20:27:26.063] java.lang.NullPointerException

 at com.haulmont.studio.backend.e.y.a(SourceFile:198)

 at com.haulmont.studio.backend.e.y.e(SourceFile:186)

 at com.haulmont.studio.backend.e.y.a(SourceFile:129)

 at sun.reflect.GeneratedMethodAccessor1801.invoke(Unknown Source)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

 at java.lang.reflect.Method.invoke(Method.java:498)

 at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

 at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

 at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

 at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

 at com.google.common.eventbus.EventBus.post(EventBus.java:275)

 at com.haulmont.studio.backend.g.run(SourceFile:62)

 at com.haulmont.studio.ui.app.App.a(SourceFile:443)

 at com.vaadin.ui.UI.accessSynchronously(UI.java:1392)

 at com.haulmont.studio.ui.app.App.accessSynchronously(SourceFile:440)

 at com.haulmont.studio.ui.app.e.a(SourceFile:28)

 at com.haulmont.studio.backend.f.c(SourceFile:58)

 at com.haulmont.studio.backend.c.run(SourceFile:104)

 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

 ...
[20:27:26.079] Unexpected error
java.lang.NullPointerException
[20:27:26.081] Ready

Does anyone have a clue why?

What I discovered was that if the Additional Data Store in the new project is not set the the error above is thrown.
The Additional Data Store settings is not copied to the new module. I have to create a new Additional Data Store Connection in the new project.

Is this how it should work?

When I opened rental-core.war I found one context.xml file in META-INF folder.
The content of this file is:


<Context>

    <!-- Database connection -->
    <Resource
      name="jdbc/CubaDS"
      type="javax.sql.DataSource"
      maxTotal="20"
      maxIdle="2"
      maxWaitMillis="5000"
      driverClassName="org.postgresql.Driver"
      url="jdbc:postgresql://192.168.10.103/rental-test"
      username="cuba"
      password="****************"/>

    <!-- Switch off session serialization -->
    <Manager pathname=""/>

</Context>

When i opened Tomcat conf/Catalina/ I found one context.xml. This is most likely the Tomcat default context.xml. There is no localhost folder.

By the way I am running the project on Ubuntu 16.04 LTS.

Tomcat Rental Test

As you can see, context.xml in your WAR does not contain definition for additional data store. Check the WAR building parameters. Do you have a “Custom context.xml path”? If so, make sure that file contains all required info.

I found out that Custom context.xml did not include the jdbc.MasterVehicle resource. I had to add it manually.
Is this normal or should this be added automatically by CUBA studio?

I also noticed that even if this settings was in place, it was not added to context.xml in tomcat 8.5.14 / 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11.

When I added it to context.xml in tomcat manually it worked as expected.

I will write a recipe on how to deploy on Linux Ubuntu if someone else is getting same problem.
I will upload it on the forum.

1 Like