Issue with resource-ref om web.xml - Failed to process bindings for metadata - websphere

I have resource-ref to the datasource in my deployment descriptor.
web.xml
<resource-ref>
<description></description>
<res-ref-name>jdbc/myAppDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
When I try to publish the ear in my local RAD - websphere environment, I'm getting below exception.
Caused by: com.ibm.wsspi.injectionengine.InjectionException: CWNEN0044E: A resource reference binding could not be found for the following resource references [jdbc/myAppDS], defined for the MyApp Web Application component.
at com.ibm.wsspi.injectionengine.InjectionProcessor.collectInjectionNBindingData(InjectionProcessor.java:1042)
at com.ibm.ws.injectionengine.InjectionEngineImpl.processBindings(InjectionEngineImpl.java:516)
... 77 more
datasource myAppDS is registered with the Websphere and test connection is also successful. Is there any reason why the war is unable to find the resource?

I solve the problem adding the datasource in this file
/WebContent/WEB-INF/ibm-web-bnd.xmi
<resRefBindings xmi:id="rr_jdbc.dataSourceName_jdbc.dataSourceName" jndiName="jdbc.dataSourceName">
<bindingResourceRef href="WEB-INF/web.xml#rr_jdbc.dataSourceName"/>
</resRefBindings>

Related

Error deploying Spring boot application in Websphere 8.5.5

I am getting following error message in stdout while starting my application in Websphere 8.5.5:
1/9/20 11:56:48:437 UTC] 000000c0 SystemOut O 11:56:48.435 [WebContainer : 3] ERROR
org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.xml'
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:545)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:494)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:464)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$7(ConfigFileApplicationListener.java:443)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$290.0000000000368730.accept(Unknown Source)
at java.lang.Iterable.forEach(Iterable.java:86)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$8(ConfigFileApplicationListener.java:443)
The version of spring boot that I am using is 2.2.2.
Why is Spring Boot trying to load the ear deployment descriptor, which is in the META-INF folder?
As M. Deinum says, the problem it is giving is because Spring Boot is trying to load the ear artifact's application.xml file to get properties and gives a parsing error as it does not have the expected format.
I have had this same error when displaying in application servers and it is solved by taking from the MANIFEST.MF file the path /META-INF
In my case, I was including the war plugin with this:
<manifestEntries>
<Class-Path>./ META-INF/</Class-Path>
</manifestEntries>
Try deleting that entry and redeploying.

Cannot find properties file in class path - Error while deploying EAR

Getting the following ERROR while trying to deploy a EAR project in JBoss AS 7.
(MSC service thread 1-5) Context initialization failed. java.io.FileNotFoundException: class path resource [.properties] cannot be opened because it does not exist
A more detailed snapshot of the errors is given below.
16:20:08,548 ERROR [org.springframework.web.servlet.DispatcherServlet]
(MSC service thread 1-5) Context initialization failed:
org.springframework.beans.factory.BeanDefinitionStoreException:
Failed to parse configuration class [xx.xx.Config]; nested exception
is java.io.FileNotFoundException: class path resource
[wwwr.properties] cannot be opened because it does not exist at
org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE] Caused by:
java.io.FileNotFoundException: class path resource [wwwr.properties]
cannot be opened because it does not exist
16:20:08,588 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MyWeb]]
(MSC service thread 1-5) StandardWrapper.Throwable:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class [com.xx.Config]; nested exception is
java.io.FileNotFoundException: class path resource [wwwr.properties]
cannot be opened because it does not exist
I am using JBoss AS7 server and MyEclipse as IDE.
Well I found the solution to be involving the following steps
1) Make sure that the property file is in the Class Path of the projects involved or at least in the modules deployed in Jboss.
1- a) Verify that the modules.xml file has the right entries
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.xx.yy">
<resources>
<resource-root path="./properties/"/>
2) Verify that the Manifest.mf file in the EAR has the required dependencies.
Dependencies: com.xx.yy
3) Clean build and Deploy to server.

Error instantiating Persistence Provider class java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

On deploying EJB application on Weblogic : 12.2.1 , I am facing the exception :
"Error instantiating the Persistence Provider class org.hibernate.ejb.HibernatePersistence of the PersistenceUnit entityManager: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence"
I have the below configuration in persistence.xml to specify persistence provider
<persistence-unit name="entityManager">
<!-- Use Hibernate persistency -->
<provider>org.hibernate.ejb.HibernatePersistence</provider>
and below in weblogic-application.xml
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>javax.persistence.*</package-name>
</prefer-application-packages>
I followed the below link to check default persistence provider set in WL , which is TopLink.
https://docs.oracle.com/middleware/1213/wls/WLACH/taskhelp/domainconfig/ConfigureDefaultJPAProvider.html
Also , tried to set classpath valriables in setDomainEnv.cmd with hibernate-jpa-api.jar, slf4j-api.jar by below configuration and restarted server .Still facing same issue.
set EXT_PRE_CLASSPATH=C:\Projects\...\lib\hibernate\hibernate-jpa-api.jar;C:\Projects\...\lib\hibernate\slf4j-api.jar
Adding the hibernate jars to the lib folder of weblogic domain can work ie hibernate.jar , hibernate-api.jar , javax.persistence.jar, com.oracle.jpa2support_ ar and the one's you set in the classpath of setDomainEnv.cmd
Source : -https://docs.oracle.com/cd/E12839_01/web.1111/e13706/classloading.htm#WLPRG324
and https://community.oracle.com/thread/1065416

Getting error when starting WAS LP server ClassNotFoundException: com.ibm.db2.jcc.DB2Driver

I am getting below error in Eclipse console when i try to start the web sphere LP server (WP 7).
[2017-10-06 12:04:46,952] [ERROR] com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.error [19] SimpleDataSource: Error while loading properties. Cause: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:278)
at com.ibatis.common.resources.Resources.classForName(Resources.java:267)
at com.ibatis.common.resources.Resources.instantiate(Resources.java:283)
at com.ibatis.common.jdbc.SimpleDataSource.initialize(SimpleDataSource.java:199)
at com.ibatis.common.jdbc.SimpleDataSource.<init>(SimpleDataSource.java:116)
at com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactory.initialize(SimpleDataSourceFactory.java:31)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$9.process(SqlMapConfigParser.java:220)
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:105)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:46)
at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
at com.pm.testdatamgt.persistence.util.SqlMapBuilder.build(SqlMapBuilder.java:67)
at com.pm.testdatamgt.persistence.util.SqlMapConfig.<clinit>(SqlMapConfig.java:71)
at com.pm.testdatamgt.persistence.util.SqlMapConfigFactory.getSqlMapInstance(SqlMapConfigFactory.java:37)
at com.pm.persistence.dao.impl.ReferenceCodeDaoImpl.getRefCatIdForSname(ReferenceCodeDaoImpl.java:95)
at com.pm..service.impl.ReferenceCodeServiceImpl.initAttributeNames(ReferenceCodeServiceImpl.java:99)
at com.pm.testdatamgt.startup.StartupServlet.loadVariables(StartupServlet.java:139)
at com.pm.testdatamgt.startup.StartupServlet.init(StartupServlet.java:125)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:332)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadOnStartupCheck(ServletWrapper.java:1428)
at com.ibm.ws.webcontainer.webapp.WebApp.doLoadOnStartupActions(WebApp.java:1205)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinally(WebApp.java:1173)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1075)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6595)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:468)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApplication(DynamicVirtualHost.java:463)
at com.ibm.ws.webcontainer.osgi.WebContainer.startWebApplication(WebContainer.java:1120)
at com.ibm.ws.webcontainer.osgi.WebContainer.access$000(WebContainer.java:104)
at com.ibm.ws.webcontainer.osgi.WebContainer$2.run(WebContainer.java:932)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:522)
at java.util.concurrent.FutureTask.run(FutureTask.java:277)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.lang.Thread.run(Thread.java:785)
I have added the required datasource in my server.xml
**<library id="DB2JCCLib">
<fileset dir="${server.config.dir}/resources/DB2" includes="db2jcc.jar, db2jcc_license_cisuz.jar, db2jcc_license_cu.jar"/>
</library>
dataSource id="db2" jndiName="jdbc/db2">
<jdbcDriver libraryRef="DB2JCCLib">
</jdbcDriver>
<properties.db2.jcc databaseName="DB2" serverName="tsoc.nnnn.com" portNumber="5002"/>
</dataSource>**
DB2 Jars are in the give location.
Am i missing something or any pointer how to debug this ??
Thanks
If using a dataSource in server configuration, Liberty would try to load data source implementation classes such as
com.ibm.db2.jcc.DB2DataSource
com.ibm.db2.jcc.DB2ConnectionPoolDataSource
com.ibm.db2.jcc.DB2XADataSource
rather than the driver class that shows in the exception,
com.ibm.db2.jcc.DB2Driver
so a good guess (lacking the exception stack) is that your application may be trying to use DriverManager.getConnection instead of using the configured dataSource. If you really want to do this (you will be losing out on many capabilities provided by the application server such as global transaction enlistment and connection pooling) then you would need to make the JDBC driver libraries directly available to your application.
For example,
<application location=...>
<classloader commonLibraryRef="DB2JCCLib"/>
</application>

Spring inside war cannot find classpath resource in an inner jar file

I have a project organized like this:
core
-- /src/main/resources/company/config/spring-config.xml
webapp
-- /WEB-INF/applicationContext.xml
The webapp depends on core.jar, which is included correctly in WEB-INF/lib when I deploy.
In web.xml I have:
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
And in applicationContext.xml I have:
<import resource="classpath:/company/config/spring-config.xml" />
But when I run, I get this error:
2012-10-04 20:03:39,156 [localhost-startStop-1] springframework.web.context.ContextLoader ERROR: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:/company/config/spring-config.xml]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [company/config/spring-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [company/config/spring-config.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
....
Caused by: java.io.FileNotFoundException: class path resource [company/config/spring-config.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:142)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
... 36 more
When spring-config.xml is in webapp, everything works fine.
I noticed the leading / is removed from some of the errors on the stack trace, and I wonder if this has anything to do with it.
Also, I am (unfortunately) using Spring 2.5, if that matters.
For future reference, I figured out the problem after much debugging. It turns out Eclipse was building my "core" library as a jar, but with a web application package layout, so instead of my resource being located here:
/company/config/spring-config.xml
it was located here:
/WEB-INF/company/config/spring-config.xml
which caused the problem. I had checked the jar a few times before, but had never noticed the sneaky "/WEB-INF" hiding in plain sight.
Removing the project and re-importing it into Eclipse (via the Maven pom.xml file) was not enough to fix the problem.
I had to manually delete the Eclipse-specific .project, .classpath, and .settings files. When I did that and re-imported the project everything was fixed.
The moral of the lesson is: ALWAYS check your resource paths when the exception says "File Not Found".

Resources