I'm using Spring 5 and Hibernate 5 together, and I'm configuring Hibernate mapping files in:
org.springframework.orm.hibernate5.LocalSessionFactoryBean like this in my applicationContext.xml file:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="mappingDirectoryLocations" value="com/myorg/division/myapp/model" />
But I'm getting this error run-time error when I deploy the WAR file to my local Weblogic server:
Deployment Message : weblogic.application.ModuleException: java.io.FileNotFoundException: ServletContext resource [/com/
myorg/division/myapp/model] cannot be resolved to absolute file path - web application archive not expanded?
This should do the work
<property name="packagesToScan" value="com.myorg.division.myapp.model" />
Related
I´m trying to inject EJB into Spring 4 application context. I've read several manuals and tutorial and I have end to an end. I do not why Spring cannot get the Remote Bean by JDNI name. When I launch the app with WildFly 10 I get a 404 error.
My Bean definitions are:
JNDI bindings for session bean named 'CursoServiceBean' in deployment unit 'subdeployment "gestion-docente-ejb.jar" of deployment "gestion-docente-ear-1.0.0-SNAPSHOT.ear"' are as follows:
java:global/gestion-docente-ear-1.0.0-SNAPSHOT/gestion-docente-ejb/CursoServiceBean!
com.formacion.ipartek.curso.CursoServiceRemote
java:app/gestion-docente-ejb/CursoServiceBean!
com.formacion.ipartek.curso.CursoServiceRemote
java:module/CursoServiceBean!
com.formacion.ipartek.curso.CursoServiceRemote
java:jboss/exported/gestion-docente-ear-1.0.0-SNAPSHOT/gestion-docente-ejb/CursoServiceBean!
com.formacion.ipartek.curso.CursoServiceRemote
java:global/gestion-docente-ear-1.0.0-SNAPSHOT/gestion-docente-ejb/CursoServiceBean
java:app/gestion-docente-ejb/CursoServiceBean
java:module/CursoServiceBean
bean id ="cursoServiceRemote" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
property name="jndiName" value="java:module/CursoServiceBean!com.formacion.ipartek.curso.CursoServiceBean" />
property name="jndiEnvironment">
props>
prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
prop key="java.naming.provider.url">ldap://localhost:9990</prop>
prop key="java.naming.security.principal">*******/prop>
prop key="java.naming.security.authentication">simple/prop>
prop key="java.naming.security.credentials">******/prop>
/props>
/property>
property name="businessInterface" value="com.formacion.ipartek.curso.CursoServiceRemote" />
</bean>
<bean id="cursoServiceImp" class="com.ipartek.formacion.service.CursoServiceImp">
property name="cursoServiceRemote" ref="cursoServiceRemote" />
</bean>
Please help.
Though jdni:jee I was able to inject the EJB bean into Spring.
<jee:jndi-lookup id="cursoServiceRemote" jndi-name="java:app/gestion-docente-ejb/CursoServiceBean" />
<bean id="cursoServiceImp" class="com.ipartek.formacion.service.CursoServiceImp">
<property name="cursoServiceRemote" ref="cursoServiceRemote" />
</bean>
One of our apps declare some parameters in Tomcat's context.xml as such:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Parameter name="defaultSchema" override="true" value="demo"/>
<Resource
auth="Container"
description="DB Connection for Local Jazzee"
driverClassName="oracle.jdbc.OracleDriver"
. . .
/>
</Context>
And then in Spring's applicationContext.xml we are able to use that parameter when we instantiate some beans:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.default_schema">${defaultSchema}</prop>
. . .
</bean>
And that works fine.
Problem I'm having is that I'm trying to duplicate this in another application, and it's not working. When I try to start the app, I get the error:
Invalid bean definition with name 'sessionFactory' defined in class path resource [db/applicationContext.xml]: Could not resolve placeholder 'defaultSchema'
It's the same developer Tomcat instance in both cases, so the Tomcat version is the same. The Spring library versions appear to be the same as well. Also, if I hardcode the schema name in the application context, it works fine. So the dataSource is fine.
Any thoughts on what might be breaking this functionality?
I had a working spring 3 application which after migration to 4.1.0.RELEASE started to cause problems. Configuration below stopped working:
<jee:jndi-lookup id="dit_properties_path" jndi-name="dit_properties_path" resource-ref="true" />
<util:properties id="systemProperties" location="classpath:system.properties" />
<util:properties id="serverProperties" location="#{dit_properties_path}"/>
After migration it seems that spring is not able to resolve spEL #{dit_properties_path}, and is showing following error:
[PropertiesFactoryBean] [INFO]: Loading properties file from ServletContext resource [/#{dit_properties_path}]
[...]is java.io.FileNotFoundException: Could not open ServletContext resource [/#{dit_properties_path}]
Jndi resource is of type java.lang.String and points to local FS (C:\someFile.properties).
Here's tomcat definition of the resource /server and context/:
<Environment name="dit_properties_path" value="file:C:\someFile.properties"
type="java.lang.String" override="true"/>
and
<ResourceLink name="dit_properties_path"
type="java.lang.String"
global="dit_properties_path" />
Do anyone have any idea how to resolve this issue?
I have several property files in my app which are often accessed by #{propertyFileId['key']} and they have to be loaded dynamically from jndi resource path.
Change from :
<util:properties id="serverProperties" location="#{dit_properties_path}"/>
to:
<util:properties id="serverProperties" location="${dit_properties_path}"/>
solved the problem. Still, can't figure out why given expression doesn't work with hash sign.
I have a spring MVC web application that has the following structure:
myapp
|-META-INF
|-WEB-INF
|-classes
| |-conf
|-application.properties
|-lib
| |-externalApp.jar
| |-conf
| |-applicationContext.xml
|
|-applicationContext.xml
|-myapp-servlet.xml
In myapp/WEB-INF/applicationContext, i imported the applicationContext.xml file that is in the jar file as shown below:
<import resource="classpath:WEB-INF/conf/applicationContext.xml" />
The beans in the imported resource work fine and i can see them in my web application's controller/service classes.
The problem i have is that the
context file in the jar file (i.e. WEB-INF/lib/externalApp.jar/applicationContext.xml) has configuration for loading a properties file. The properties have to be set by the web application so the properties file is in the webapp. The configuration in the jar file's context file looks like this:
I want the above property to load the property file that is in the web application so i set its value to be as shown below:
<bean class="com.myapp.ExternalAppPropertyPlaceholderConfigurer">
<property name="location" value="classpath:conf/application.properties" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
With the above setting, the classes in the jar file that expect these properties to be availbe still cant get access to the properties.
The question i guess is how can i get the properties file that is in WEB-INF/classes/conf/application.properties to be accessible to the objects in the jar file that is located in WEB-INF/lib/externalApp.jar.
Looking at the stack traces i am getting, it looks as though the objects referred in the imported context file are loaded first before the properties are loaded which is not i want.
Thanks.
You can use the classpath*: prefix like this
<bean class="com.myapp.ExternalAppPropertyPlaceholderConfigurer">
<property name="location" value="classpath*:conf/application.properties" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
EDIT
Since your conf/application.properties is in your web app, you must define it in your web-app applicationContext (not in the jar as you do now). And define it before importing the applicationContext of your jar. i.e. put something like this in your web-app applicationContext:
<bean class="com.myapp.ExternalAppPropertyPlaceholderConfigurer">
<property name="location" value="classpath:conf/application.properties" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<import resource="classpath*:/conf/applicationContext.xml" />
and remove the declaration of the properties from your jar applicationContext.
I have following in my applicaionContext.xml
<bean id="IbatisDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#123.210.85.56:1522:ORCL"/>
<property name="username" value="mydb"/>
<property name="password" value="mydbpwd"/>
</bean>
<bean id="myMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sql-map-config-oracle.xml"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
then in my code I have:
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
SqlMapClient sqlclient = (SqlMapClient) ctx.getBean("myMapClient");
doing this gives me the following error:
Error creating bean with name
'myMapClient' defined in class
path resource
[applicationContext.xml]: Invocation
of init method failed; nested
exception is
java.lang.NoClassDefFoundError:
com/iplanet/ias/admin/common/ASException
I don't understand why is it looking for that class? I am trying to do everything outside the container. So it should not even be looking for that class...but nonetheless just to make it work I tried looking for class called ASException so I could put it on the classpath but no where can I find ASException class.
Any pointers?
Images of stack trace and my compile test / run test libs
Edit
Solution:
Even though I thought everything was outside the container...there was ONE thing that was not outside the container.
Notice the property configLocation:
<property name="configLocation" value="classpath:sql-map-config-oracle.xml"/>
actual content of sql-map-config-oracle.xml is
<sqlMapConfig>
<settings enhancementEnabled="true" useStatementNamespaces="true" />
<transactionManager type="JDBC">
<dataSource type="JNDI">
<property name="DataSource" value="my/jndi/mydb" />
</dataSource>
</transactionManager>
<sqlMap resource="somemapping.xml"/>
</sqlMapConfig>
JNDI stuff does not need to be there!
sql-map-config-oracle.xml should simply be:
<sqlMapConfig>
<settings enhancementEnabled="true" useStatementNamespaces="true" />
<sqlMap resource="somemapping.xml"/>
</sqlMapConfig>
You definitely have a runtime dependency issue as #Cletus said org.springframework.orm.ibatis.SqlMapClientFactoryBean was compiled with com.iplanet.ias.admin.common.ASException but now you don't have it in your classpath -- Spring can't find it. You should Look at the source for SqlMapClientFactoryBean to see where ASException is called -- Spring should have a dist with all it's dependencies in it, you can also look in there when doing your investigation.
This class was found during compilation but not during running:
com/iplanet/ias/admin/common/ASException
So when you're running the program, it can't seem to find this class, which belongs to the Sun app or portal server that you're using. In short: it's a classpath error.