spring.xml

Hi; I deployed war file of simple application with single entity with two attribute to test the deployment process of war file on the platform.

I did not change any configuration of xml file, i just created war file as stated in document and deployed it in a server. However i am getting this error message. i am wondering if i need to add bean configuration of entity factory in spring.xml file.

INFO myhostspot.com-startStop-1 org.apache.catalina.startup.HostConfig - Deploying web application archive /home/kyz/tomcat/webapps/myhostspot.com/app-core.war
INFO myhostspot.com-startStop-1 org.apache.catalina.core.ContainerBase.[Catalina].[myhostspot.com].[/app-core] - No Spring WebApplicationInitializer types detected on classpath
ERROR myhostspot.com-startStop-1 org.apache.catalina.core.ContainerBase.[Catalina].[myhostspot.com].[/app-core] - Exception sending context initialized event to listener instance of class com.haulmont.cuba.core.sys.AppContextLoader
java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [cuba-spring.xml]: Cannot resolve reference to bean 'cubaDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource' defined in class path resource [cuba-spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/CubaDS] is not bound in this Context. Unable to find [jdbc].
	at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:60)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4751)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5175)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)

presistant.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">  
  <persistence-unit name="testWar" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
.....
    <exclude-unlisted-classes/>
    <properties>
      <property name="eclipselink.cache.shared.default" value="false"/>
      <property name="eclipselink.session-event-listener" value="com.haulmont.cuba.core.sys.persistence.EclipseLinkSessionEventListener"/>
      <property name="eclipselink.target-database" value="com.haulmont.cuba.core.sys.persistence.CubaPostgreSQLPlatform"/>
      <property name="eclipselink.weaving" value="static"/>
      <property name="eclipselink.logging.logger" value="com.haulmont.cuba.core.sys.logging.EclipseLinkLog"/>
    </properties>
  </persistence-unit> 
</persistence>

==============spring.xml file is as follows====

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsd">

    <!-- Annotation-based beans -->
    <context:component-scan base-package="com.company.testwar"/>

</beans>

thks

Hello.

Could you please tell me which server do you use - Tomcat, Jetty or anything else?

Thanks

I am using tomcat 8

The problem is that platform can not find data source name in JNDI context.

WAR file does not contain context.xml file (specific for Tomcat), because it might be deployed to any container (Jetty, WebSphere, etc).

To fix your issue, you should put context.xml to tomcat/conf/Catalina/localhost/ folder. The context.xml file is placed in /modules/core/web/META-INF/ folder.

Then you should rename the file to app-core.xml (if you deploy 2 separate WAR) or app.xml (if you deploy single WAR).

1 Like

Hello.

Did you have any success with above?

Adding includeContextXml to buildWar doesnt resolve the above issue

task buildWar(type: CubaWarBuilding) {

includeJdbcDriver = true
includeContextXml = true
}

so I copy the /modules/core/web/META-INF/context.xml
to tomcat/conf/Catalina/localhost/app.xml
but I have other apps deployed to the tomcat server, do I still need to namep it “app.xml” ?