While migrating from EJB with spring to POJO , I read every where that just changing this configuration will work :
<bean id="sapFeedBean" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean" lazy-init="true">
<property name="jndiName" value="ejb/sapBean" />
<property name="resourceRef" value="false" />
<property name="businessInterface" value="com.aa.inflightsales.sap.SapBusiness" />
<property name="lookupHomeOnStartup" value="false" />
</bean>
but how to do this , I am trying to create bean of the POJO class , but how can I define the business interface , as interface injection is not supported by spring.
Just define the business methods in this interface which should be implemented by the business class and when you need it just use a reference to the interface with the convenient annotation and the framework will inject the implementation.
Related
Like described in the linked article below, with Java configuration it is possible to override the JobRepository bean by extending DefaultBatchConfigurer and overriding createJobRepository.
How can this be achieved in a context.xml file where the jobrepository bean is defined like this
<bean id="jobRepository_new"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="databaseType" value="Oracle" />
<property name="dataSource" ref="dataSource-batch" />
<property name="transactionManager" ref="transactionManager" />
<property name="tablePrefix" value="BATCH_" />
<property name="lobHandler" ref="oracleLobHandler" />
</bean>
?
Can't serialize access for this transaction when running single job, SERIALIZED isolation level
Unlike with the Java configuration style, there is nothing provided by default (that you can override) when you use the XML configuration style.
So you just need configure the job repository bean as needed like shown in the snippet you shared.
I am trying to implement a Spring application with RMI and AOP. I am having problems with my server component. If the service interface which i want to expose does not extend Remote and the methods do not throw an RemoteException, I am getting the error:
UnknownAdviceTypeException: Advice object [org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#1f90645] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor]
if the interface extends Remote it works just fine with starting and so on.
My application.xml has only one bean declared:
<bean id="testService" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="TestService" />
<property name="service" ref="testServiceImpl"/>
<property name="serviceInterface"
value="xxx.service.TestService" />
</bean>
My interface only has the #Transactional annotation, while the implementation has the #Service annotation.
In my client i get errors as well. Here i get an error of a not unique bean: found bean testService and testServiceImpl. My client.xml looks like this:
<bean class="xxx.start.Client">
<property name="testService" ref="testService"/>
</bean>
<bean id="testService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://localhost:1099/TestService"/>
<property name="serviceInterface" value="xxx.service.TestService"/>
</bean>
I followed this guide, but go the errors above. If you could help me id be very glad. If i run my JUnit test without RMI, its working all fine
i found out why it throws the error. it was because i had default-autowiring set to byType, but the RmiServiceExporter should have autowire=no
I have a problem with Spring.
I have two separate interfaces, findUnconditionalDiscountValuesStrategy and findConditionalDiscountValuesStrategy. These interfaces are implemented in the same class MmfgFindPricingWithCurrentPriceFactoryStrategy.
This is declared in the spring configuration file like this:
<alias name="mmfgFindPricingWithCurrentPriceFactoryStrategy" alias="currentFactoryFindPricingStrategy"/>
<bean id="mmfgFindPricingWithCurrentPriceFactoryStrategy" class="com.mmfg.mmfgacceleratorcore.order.strategies.calculation.impl.MmfgFindPricingWithCurrentPriceFactoryStrategy" parent="abstractBusinessService">
<property name="findPricingWithCurrentPriceFactoryStrategy" ref="original-currentFactoryFindPricingStrategy"/>
<property name="configurationService" ref="configurationService"/>
<property name="mmfgSessionService" ref="mmfgSessionService"/>
<property name="mmfgUtilsDao" ref="mmfgUtilsDao" />
</bean>
Now, I use the two interfaces in a class
private FindUnconditionalDiscountValuesStrategy findUnconditionalDiscountValuesStrategy;
private FindConditionalDiscountValuesStrategy findConditionalDiscountValueStrategy;
with getter and setter (getter protected and setter #Required).
Now I have declared this class in this way in the spring configuration file:
<bean id="mmfgOrderCalculationStrategy" class="com.mmfg.mmfgacceleratorcore.order.strategies.calculation.impl.DefaultMmfgOrderCalculationStrategy">
<property name="findUnconditionalDiscountValuesStrategy" ref="currentFactoryFindPricingStrategy"/>
<property name="findConditionalDiscountValuesStrategy" ref="currentFactoryFindPricingStrategy"/>
<property name="modelService" ref="modelService" />
<property name="commonI18NService" ref="commonI18NService" />
<property name="calculationService" ref="calculationService"/>
</bean>
the ref is the same for the two interfaces, because the implementation class is the same.
But at runtime I obtain this error:
org.springframework.beans.factory.BeanInitializationException: Property 'findConditionalDiscountValueStrategy' is required for bean 'mmfgOrderCalculationStrategy'
How I have to declare the ref in the two properties?
There is a typo error. My property is called findConditionalDiscountValueStrategy. But in the class the name is findConditionalDiscountValuesStrategy.
After switching to Spring 3.1 Eclipse started to complain about our current implementation of TokenBasedRememberMeServices. The class extending it has a parameterless constructor which has been deprecated. The new constructor accepts two params.
An extract from applicationContext-security.xml :
<bean id="rememberMeServices" class="MyRememberMeServices"
p:key="${rememberMeServices.key}">
<property name="userDetailsService" ref="userDetailsService"/>
</bean>
What's the easiest way of moving to the new API?
Use constructor injection:
<bean id="rememberMeServices" class="MyRememberMeServices">
<constructor-arg value="${rememberMeServices.key}" />
<constructor-arg ref="userDetailsService" />
</bean>
Obviously you'd add a corresponding constructor in your MyRememberMeServices which calls the parent class.
Besides Spring 3.1 and ehcache-spring-annotations, do we have other alternatives that are other than EhCache and Spring?
Have you looked at Spring-AOP based solutions? You can create an auto-proxy object in your Spring applicationContext using the org.springframework.aop.support.RegexpMethodPointcutAdvisor and then make an object that implements AfterReturningAdvice, ThrowsAdvice and MethodBeforeAdvice.
Use that object to monitor function calls and exits and cache what information you want.
<bean name="cacheHandler" class="org.yourname.CachingInterceptor" />
<bean id="cacheAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice" ref="cacheHandler" />
<property name="pattern" value="org.yourname.regex.of.stuff.you.want.cached.*" />
</bean>
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />