replaced-method question in spring 3 - spring

Excuse me. I'm a beginner of spring. Now, there's some question in it.
I'm reading Spring in action and try the code in MyEclipse. But when I try the code of replaced-method, there's a error.
<bean id="harry" class="com.springinaction.sprintidol.Magician">
<property name="magicBox" ref="magicBox" />
<property name="magicWords" value="Bippity boppity boo" />
</bean>
<bean id="magicBox" class="com.springinaction.sprintidol.MagicBoxImpl">
<replaced-method name="getContents" replacer="tigerReplacer" />
</bean>
<bean id="tigerReplacer" class="com.springinaction.sprintidol.TigerReplacer" />
This is the applicationContext.xml. And the exception as followed:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stevie' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
All of the code come from the book. Why do I get the exception? And how to solve?
Thanks.

I found the reason. Because I didn't include the Spring 3.0 Persistence Core Libraries.Thanks all the same.

Related

JNDI lookup failure

i would be grateful if someone can help me rectify the issue in my code. Not sure where I'm going wrong.
Currently my persistence.xml contains
<property name="hibernate.transaction.manager_lookup_class" value="#####.hibernate.JbossTSTransactionManagerLookup"/>
<property name="hibernate.current_session_context_class" value="jta"/>
along with
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="####"/>
<property name="jpaDialect" ref="jpaDialect"/>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:comp/env/TransactionManager"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Context initialization failed : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [###XMLConfig.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:comp/env/TransactionManager]; nested exception is org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager]
Caused by: org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:comp/env/TransactionManager]; nested exception is org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager]
at org.springframework.transaction.jta.JtaTransactionManager.lookupTransactionManager(JtaTransactionManager.java:598)
Caused by: org.springframework.jndi.TypeMismatchNamingException: Object of type [class com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple] available at JNDI location [java:comp/env/TransactionManager] is not assignable to [javax.transaction.TransactionManager] at org.springframework.jndi.JndiTemplate.lookup()
at org.springframework.transaction.jta.JtaTransactionManager.lookupTransactionManager()
Looks like there is some issue with the classpath of your project. Check if there are two versions of the same dependency in your project. In my case I had multiple versions of the jboss-transaction jar in the classpath, keeping just one version of it fixed the issue for me. Check if there is any transitive dependency which is causing this issue which you can exclude in your maven pom.

Trying to deploy a Spring Service on WSO2 Application Service

I'm trying to deploy a Spring Service in WSO2 Application Service. I did THIS tutorial and the app works fine on Eclipse, but when I try to deploy it on WSO2 I get this error:
Cannot load Spring beans. Please check the Spring context
configuration file and verify that the defined Spring beans exist in
the .jar file.
I unziped de .jar file and JdbcCustomerDAO class is there with all the others.
Spring context:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="customerDAO" class="com.mkyong.customer.dao.impl.JdbcCustomerDAO">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="url" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
</beans>
I also tried to include spring and mysql-connector-java jars on /repository/components/extensions as says HERE.
EDIT:
ERROR {org.wso2.carbon.springservices.ui.SpringServiceMaker} - Cannot
load Spring beans. Please check the Spring context configuration file
and verify that the defined Spring beans exist in the .jar file.
{org.wso2.carbon.springservices.ui.SpringServiceMaker}
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot
find class
[org.springframework.jdbc.datasource.DriverManagerDataSource] for bean
with name 'dataSource' defined in resource loaded through InputStream;
nested exception is java.lang.ClassNotFoundException:
org.springframework.jdbc.datasource.DriverManagerDataSource
Looks like it couldn't find spring-jdbc, so I added the jar to extensions but now I get this error:
ERROR {org.wso2.carbon.springservices.ui.SpringServiceMaker} - Cannot load
Spring beans. Please check the Spring context configuration file and
verify that the defined Spring beans exist in the .jar file.
{org.wso2.carbon.springservices.ui.SpringServiceMaker}
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource' defined in resource loaded
through InputStream: Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class
[org.springframework.jdbc.datasource.DriverManagerDataSource]:
Constructor threw exception; nested exception is
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
I understand that commons.logging is also missing, but when I try to add it to extensions, WSO2 doesn't start. I get a lot of
Log4j:ERROR Could not instantiate...

Unable to create transactionManager (JTA) bean using Spring 2.5.6 on JBOSS EAP 6.3

I'm getting this error:
Error creating bean with name 'wsJtaTm' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class
[org.springframework.transaction.jta.JotmFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: stub class initialization failed
I'm using the following piece of code to create txnmanager bean for Jboss
Datasource and JNDI correctly loading and configured.
applicationcontext.xml
<bean id="wsJtaTm" class="org.springframework.transaction.jta.JotmFactoryBean" />
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="wsJtaTm" />
</bean>
What is wrong with my code?

Configuration Issue during spring upgrade

Below is the issue i am facing during the spring upgrade.I feel the issue is with the doctype.Please suggest
Bean 'cdqiPerformanceMonitor'; nested exception is
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Old 1.x 'singleton' attribute in use - upgrade to
'scope' declaration
Offending resource: ServletContext resource [/WEB-
INF/applicationContext.xml]
Below is the application context xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="cdqiPerformanceMonitor"
class="com.tms.cdqi.framework.aop.interceptor.CDQIPerformanceMonitorInterceptor" />
<bean id="cdqiApplicationContextFactory"class="com.tms.cdqi.framework.context.CDQIApplicationContextFactoryImpl" />
<bean id="commandInvoker"class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean"
lazy-init="true">
<property name="jndiName">
<value>ejb/CommandInvokerLocal</value>
</property>
<property name="businessInterface">
<value>
com.tms.cdqi.application.command.invoker.CommandInvoker
</value>
</property>
</bean>
</beans>
Below is the stack trace
listener org.springframework.web.context.ContextLoaderListener
failed:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unexpected failure during bean definition parsing
Offending resource: ServletContext resource [/WEB-
INF/applicationContext.xml]
Bean 'cdqiPerformanceMonitor'; nested exception is
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Old 1.x 'singleton' attribute in use - upgrade to
'scope' declaration
Offending resource: ServletContext resource [/WEB-
INF/applicationContext.xml]
See SPR-12167. Spring no longer accepts singleton="true", so you must use scope="singleton" instead.

ClassNotFoundException Issue with Spring DI Demo

I'm not able to run the program.
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.tutorialspoint.HelloWorld] for bean with name 'hello' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException:
Your bean definition must point to the class not the package name
<bean id="hello" class="com.tutorialspoint.HelloWorld.MainApp">
<property name="message" value="Hello Man"></property>
</bean>
your Spring Beans Configuration is perfect but you have to give correct path for ApplicationContext in MainApp class according to your code your path should be "main/resource/beans.xml" . Hope this will work...

Resources