Error injecting remote EJB into Spring - java

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>

Related

WebXmlMappableAttributesRetriever webXmlInputStream missing in spring security 4.2.0

In Spring Security 2.0.7, I am configure the WebXmlMappableAttributesRetriever as follow:
<bean id="mappableRolesRetriever"
class="org.springframework.security.ui.preauth.j2ee.WebXmlMappableAttributesRetriever">
<property name="webXmlInputStream">
<bean factory-bean="webXmlResource" factory-method="getInputStream"/>
</property>
</bean>
<bean id="webXmlResource" class="org.springframework.web.context.support.ServletContextResource">
<constructor-arg ref="servletContext"/>
<constructor-arg value="/WEB-INF/web.xml"/>
</bean>
<bean id="servletContext" class="org.springframework.web.context.support.ServletContextFactoryBean"/>
However, when come to spring security 4.2.0, the webXmlInputStream property no longer exist in WebXmlMappableAttributesRetriever. I go to check the source code in WebXmlMappableAttributesRetriever, the afterPropertiesSet() method and I saw it doing something like retrieving data from /WEB-INF/web.xml like what I set in Spring security 2.
Resource webXml = resourceLoader.getResource("/WEB-INF/web.xml");
Document doc = getDocument(webXml.getInputStream());
Does this means that I no longer need to do this configuration in Spring security 4?

Hibernate LocalSessionFactoryBean, setMappingDirectoryLocations doesn't seem to be working

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

"No message found under code" if class is not in base-package of servlet-context. Why?

It is the part of servlet-context relating to internalisation.
<context:component-scan base-package="com.project.controllers" />
<interceptors>
<beans:bean
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
p:paramName="lang" />
<beans:bean
class="org.springframework.web.servlet.theme.ThemeChangeInterceptor" />
</interceptors>
<!-- i18n -->
<beans:bean
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
id="messageSource" p:basenames="WEB-INF/i18n/messages, WEB-INF/i18n/application"
p:fallbackToSystemLocale="false" />
<beans:bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
id="localResolver" p:cookieName="locale" />
The root-context:
<context:component-scan base-package="com.project"/>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
If I try to get message within jsp page or within controllers package everything is ok:
messageSource.getMessage("message.code", new Object[] {}, locale)
But it does not work out of the package defined in servlet-context, though messageSource bean is autowired.
Does it mean that root-context has default messageSource and in servlet-context it is overriden only for particular package?
Configuration defined in ServletContext for a specific controller always overrides the configuration of the rootContext. Also it is private to the root context.
The configuration you put in the servlet context is specific to that particular servlet/controller. If you need a global functionality for internationalization you should define the messageSource bean in the root Context.
When an ApplicationContext is loaded, it automatically searches for a MessageSource bean defined in the context. The bean must have the name messageSource. If such a bean is found, all calls to the preceding methods are delegated to the message source. If no message source is found, the ApplicationContext attempts to find a parent containing a bean with the same name. If it does, it uses that bean as the MessageSource. If the ApplicationContext cannot find any source for messages, an empty DelegatingMessageSource is instantiated in order to be able to accept calls to the methods defined above.

Inject spring bean into #Controller via applicationContext.xml

In my dispatcher-servlet.xml I defined a bean as follows:
<bean id="worplacementDAO" class="com.mycompany.maventestwebapp.db.dao">
<property name="dataSource" value="dataSource" />
</bean>
Is it possible to inject the bean into a controller via applicationContext configuration file, without using #Autowired?
Simple answer - No.
You can implement BeanPostProcessor to do something with your beans (e.g. inject dependency). Or you can manually register the bean as <bean> instead of letting component-scan do that for you. But that is all you can do.

Inject property into non managed Spring xml

I am having xml. (Ehcache.xml)
I want to inject into it property from property file(on the classpath).
However since this xml is not a Spring managed bean I am not able to do so.
Any recommendations how to overcome this?
the xml:
...
properties="peerDiscovery=manual,rmiUrls=//**${other.node.hostname}**:41001/org.jasig.cas.ticket.ServiceTicket|//**${other.node.hostname}**:41001/org.jasig.cas.ticket.TicketGrantingTicket"
propertySeparator="," />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="port=41001,socketTimeoutMillis=5000" />
</ehcache>
I want to inject ${other.node.hostname} from another properties file.
but I get this on runtime:
Caused by: java.net.URISyntaxException: Illegal character in authority at index 2: //${other.node.hostname}:41001/org.jasig.cas.ticket.TicketGrantingTicket
thanks,
ray.
in the ehcache.xml it won't work because it's not spring configuration. But if you define the equivalent configuration in spring instead of the ehcache file it should work:
<context:property-placeholder location="classpath:config.properties"/>
<bean id="myCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager" ref="cacheManager"/>
<property name="maxElementsInMemory" value="${cache.maxMemoryElements}"/>
</bean>
the best is to use the ehcache.xml file the least possible and configure everything in spring, as most of the options in the file have a spring equivalent.

Categories

Resources