Impossible to inject Slick DatabaseConfigProvider in scaldi and play 2.5 - playback

I'm having a issue to inject the slick DatabaseConfigProvider in Scaldi. It was working fine in play 2.4 but I had to migrate to 2.5.
Here is my configuration :
play 2.5.3
scaldi-play 0.5.15
play-slick 2.0.0
My application-conf:
slick.dbs.devpostgres.driver="slick.driver.PostgresDriver$" # You must provide the required Slick driver!
slick.dbs.devpostgres.db.driver=org.postgresql.Driver
slick.dbs.devpostgres.db.url="jdbc:postgresql://localhost:5432/test"
slick.dbs.devpostgres.db.user=postgres
slick.dbs.devpostgres.db.password="pwd"
play.application.loader = scaldi.play.ScaldiApplicationLoader
play.modules {
enabled += modules.ApplicationModule
enabled += scaldi.play.ControllerInjector
}
My Scaldi ApplicationModule :
class ApplicationModule extends Module {
binding to new ObjectDao
binding to new UserDao
bind[DatabaseConfig[_]] to DatabaseConfigProvider.get[JdbcProfile]("devpostgres")(inject[Application])
}
My ObjectDao extended by my UserDao class:
class ObjectDao(implicit inj: Injector) extends Injectable {
// Using the same database connection for every DAO extending this class
val dbConfig = inject[DatabaseConfigProvider].get[JdbcProfile]
val db = dbConfig.db
}
And finally, my UserDao :
class UserDao(implicit inj: Injector) extends ObjectDao {
import dbConfig.driver.api._
private val users = TableQuery[UserTable]
...
}
Error while starting the application :
Unexpected exception
InjectException: No binding found with following identifiers:
* TypeTagIdentifier(play.api.db.slick.DatabaseConfigProvider)
No source available, here is the exception stack trace:
->scaldi.InjectException: No binding found with following identifiers:
* TypeTagIdentifier(play.api.db.slick.DatabaseConfigProvider)
scaldi.Injectable$class.noBindingFound(Injectable.scala:180)
dao.ObjectDao.noBindingFound(ObjectDao.scala:7)
scaldi.Injectable$$anonfun$inject$1$$anonfun$apply$1.apply(Injectable.scala:45)
scaldi.Injectable$$anonfun$inject$1$$anonfun$apply$1.apply(Injectable.scala:45)
scala.Option.getOrElse(Option.scala:121)
scaldi.Injectable$class.injectWithDefault(Injectable.scala:152)
dao.ObjectDao.injectWithDefault(ObjectDao.scala:7)
scaldi.Injectable$$anonfun$inject$1.apply(Injectable.scala:45)
scaldi.Injectable$$anonfun$inject$1.apply(Injectable.scala:45)
scaldi.util.Util$WorkflowHelper$.$bar$greater$extension(Util.scala:7)
scaldi.Injectable$class.inject(Injectable.scala:45)
dao.ObjectDao.inject(ObjectDao.scala:7)
dao.ObjectDao.(ObjectDao.scala:9)
dao.UserDao.(AdminRepo.scala:13)
modules.ApplicationModule$$anonfun$3.apply(ApplicationModule.scala:64)
modules.ApplicationModule$$anonfun$3.apply(ApplicationModule.scala:64)
scaldi.LazyBinding$$anonfun$target$2.apply(Binding.scala:180)
scaldi.LazyBinding$$anonfun$target$2.apply(Binding.scala:180)
scala.Option.map(Option.scala:146)
scaldi.LazyBinding.target$lzycompute(Binding.scala:180)
scaldi.LazyBinding.target(Binding.scala:180)
scaldi.LazyBinding.get(Binding.scala:196)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scala.Option.flatMap(Option.scala:171)
scaldi.Injectable$class.injectWithDefault(Injectable.scala:152)
controllers.Application.injectWithDefault(Application.scala:16)
scaldi.Injectable$$anonfun$inject$1.apply(Injectable.scala:45)
scaldi.Injectable$$anonfun$inject$1.apply(Injectable.scala:45)
scaldi.util.Util$WorkflowHelper$.$bar$greater$extension(Util.scala:7)
scaldi.Injectable$class.inject(Injectable.scala:45)
controllers.Application.inject(Application.scala:16)
controllers.Application.(Application.scala:18)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:422)
scala.reflect.runtime.JavaMirrors$JavaMirror$JavaVanillaMethodMirror1.jinvokeraw(JavaMirrors.scala:374)
scala.reflect.runtime.JavaMirrors$JavaMirror$JavaMethodMirror.jinvoke(JavaMirrors.scala:339)
scala.reflect.runtime.JavaMirrors$JavaMirror$JavaVanillaMethodMirror.apply(JavaMirrors.scala:355)
scaldi.play.ControllerInjector$$anonfun$4.apply(ControllerInjector.scala:62)
scaldi.play.ControllerInjector$$anonfun$4.apply(ControllerInjector.scala:53)
scala.Option.map(Option.scala:146)
scaldi.play.ControllerInjector.scaldi$play$ControllerInjector$$createBinding(ControllerInjector.scala:53)
scaldi.play.ControllerInjector$$anonfun$getBindingInternal$3$$anonfun$apply$3.apply(ControllerInjector.scala:33)
scaldi.play.ControllerInjector$$anonfun$getBindingInternal$3$$anonfun$apply$3.apply(ControllerInjector.scala:32)
scala.Option.getOrElse(Option.scala:121)
scaldi.play.ControllerInjector$$anonfun$getBindingInternal$3.apply(ControllerInjector.scala:32)
scaldi.play.ControllerInjector$$anonfun$getBindingInternal$3.apply(ControllerInjector.scala:31)
scala.Option.getOrElse(Option.scala:121)
scaldi.play.ControllerInjector.getBindingInternal(ControllerInjector.scala:30)
scaldi.MutableInjectorAggregation$$anonfun$getBindingInternal$2.apply(Injector.scala:85)
scaldi.MutableInjectorAggregation$$anonfun$getBindingInternal$2.apply(Injector.scala:84)
scala.collection.Iterator$$anon$11.next(Iterator.scala:370)
scala.collection.TraversableOnce$class.collectFirst(TraversableOnce.scala:143)
scala.collection.SeqViewLike$AbstractTransformed.collectFirst(SeqViewLike.scala:37)
scaldi.MutableInjectorAggregation.getBindingInternal(Injector.scala:87)
scaldi.InjectorWithLifecycle$$anonfun$getBinding$3.apply(Injector.scala:170)
scaldi.InjectorWithLifecycle$$anonfun$getBinding$3.apply(Injector.scala:170)
scaldi.util.Util$WorkflowHelper$.$bar$greater$extension(Util.scala:7)
scaldi.InjectorWithLifecycle$class.getBinding(Injector.scala:170)
scaldi.MutableInjectorAggregation.getBinding(Injector.scala:78)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$injectSymbol(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scala.collection.immutable.List.map(List.scala:277)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$createNewInstance(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding.initNewInstance(AnnotationBinding.scala:119)
scaldi.jsr330.AnnotationBinding.getInstance(AnnotationBinding.scala:111)
scaldi.jsr330.AnnotationBinding.get(AnnotationBinding.scala:85)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1$$anonfun$apply$2.apply(ScaldiInjector.scala:42)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1$$anonfun$apply$2.apply(ScaldiInjector.scala:42)
scala.Option.map(Option.scala:146)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1.apply(ScaldiInjector.scala:42)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1.apply(ScaldiInjector.scala:38)
play.utils.Threads$.withContextClassLoader(Threads.scala:21)
scaldi.play.ScaldiInjector.scaldi$play$ScaldiInjector$$getActualBinding(ScaldiInjector.scala:38)
scaldi.play.ScaldiInjector$$anonfun$instanceOf$1.apply(ScaldiInjector.scala:23)
scaldi.play.ScaldiInjector$$anonfun$instanceOf$1.apply(ScaldiInjector.scala:22)
scala.Option.getOrElse(Option.scala:121)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:22)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:18)
play.api.inject.RoutesProvider$$anonfun$2.apply(BuiltinModule.scala:82)
play.api.inject.RoutesProvider$$anonfun$2.apply(BuiltinModule.scala:82)
scala.Option.fold(Option.scala:158)
play.api.inject.RoutesProvider.get$lzycompute(BuiltinModule.scala:82)
play.api.inject.RoutesProvider.get(BuiltinModule.scala:78)
play.api.inject.RoutesProvider.get(BuiltinModule.scala:77)
scaldi.play.ScaldiBuilder$$anonfun$6$$anonfun$apply$1$$anonfun$apply$12.apply(ScaldiBuilder.scala:227)
scaldi.ProviderBinding.target(Binding.scala:217)
scaldi.ProviderBinding.get(Binding.scala:223)
scaldi.ProviderBinding.get(Binding.scala:213)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.jsr330.AnnotationBinding$$anonfun$scaldi$jsr330$AnnotationBinding$$injectSymbol$2.apply(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$scaldi$jsr330$AnnotationBinding$$injectSymbol$2.apply(AnnotationBinding.scala:171)
scala.Option.flatMap(Option.scala:171)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$injectSymbol(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scala.collection.immutable.List.map(List.scala:273)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$createNewInstance(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding.initNewInstance(AnnotationBinding.scala:119)
scaldi.jsr330.AnnotationBinding.getInstance(AnnotationBinding.scala:111)
scaldi.jsr330.AnnotationBinding.get(AnnotationBinding.scala:85)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scala.Option.flatMap(Option.scala:171)
scaldi.Injectable$class.injectWithDefault(Injectable.scala:152)
scaldi.play.ScaldiBuilder$.injectWithDefault(ScaldiBuilder.scala:128)
scaldi.play.ScaldiBuilder$$anonfun$6$$anonfun$apply$1$$anonfun$apply$18.apply(ScaldiBuilder.scala:240)
scaldi.ProviderBinding.target(Binding.scala:217)
scaldi.ProviderBinding.get(Binding.scala:223)
scaldi.ProviderBinding.get(Binding.scala:213)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.jsr330.AnnotationBinding$$anonfun$scaldi$jsr330$AnnotationBinding$$injectSymbol$2.apply(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$scaldi$jsr330$AnnotationBinding$$injectSymbol$2.apply(AnnotationBinding.scala:171)
scala.Option.flatMap(Option.scala:171)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$injectSymbol(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scala.collection.immutable.List.map(List.scala:277)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$createNewInstance(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding.initNewInstance(AnnotationBinding.scala:119)
scaldi.jsr330.AnnotationBinding.getInstance(AnnotationBinding.scala:111)
scaldi.jsr330.AnnotationBinding.get(AnnotationBinding.scala:85)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scala.Option.flatMap(Option.scala:171)
scaldi.Injectable$class.injectWithDefault(Injectable.scala:152)
scaldi.play.ScaldiBuilder$.injectWithDefault(ScaldiBuilder.scala:128)
scaldi.play.ScaldiBuilder$$anonfun$6$$anonfun$apply$1$$anonfun$apply$18.apply(ScaldiBuilder.scala:240)
scaldi.ProviderBinding.target(Binding.scala:217)
scaldi.ProviderBinding.get(Binding.scala:223)
scaldi.ProviderBinding.get(Binding.scala:213)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1$$anonfun$apply$2.apply(ScaldiInjector.scala:42)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1$$anonfun$apply$2.apply(ScaldiInjector.scala:42)
scala.Option.map(Option.scala:146)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1.apply(ScaldiInjector.scala:42)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1.apply(ScaldiInjector.scala:38)
play.utils.Threads$.withContextClassLoader(Threads.scala:21)
scaldi.play.ScaldiInjector.scaldi$play$ScaldiInjector$$getActualBinding(ScaldiInjector.scala:38)
scaldi.play.ScaldiInjector$$anonfun$instanceOf$1.apply(ScaldiInjector.scala:23)
scaldi.play.ScaldiInjector$$anonfun$instanceOf$1.apply(ScaldiInjector.scala:22)
scala.Option.getOrElse(Option.scala:121)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:22)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:18)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:15)
scaldi.play.ScaldiApplicationBuilder.build(ScaldiApplicationBuilder.scala:88)
scaldi.play.ScaldiApplicationLoader.load(ScaldiApplicationLoader.scala:19)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:158)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:155)
play.utils.Threads$.withContextClassLoader(Threads.scala:21)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:155)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:126)
scala.Option.map(Option.scala:146)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:126)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:124)
scala.util.Success.flatMap(Try.scala:231)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:124)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:116)
scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Am I missing something here ?
Thanks in advance for your help.
Much appreciated !

Related

CastException: org.springframework.beans.factory.BeanDefinitionStoreException incompatible with org.springframework.web.context.WebApplicationContext

I am using open JDK11, Spring 3.1 version, with below code. Using tomcat 8.5
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
public class TomcatStopListener extends ContextLoaderListener {
public void contextDestroyed(ServletContextEvent event) {
try {
WebApplicationContext context = (WebApplicationContext) event.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
Getting below runtime exception for the above code.
java.lang.ClassCastException: org.springframework.beans.factory.BeanDefinitionStoreException incompatible with org.springframework.web.context.WebApplicationContext
at com.nsn.servlets.TomcatStopListener.contextDestroyed(TomcatStopListener.java:28)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4811)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5467)
please suggest, thank you
**
Update 26th Sept 2022
**
I have updated the below api, but getting array index out of bound exception.
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext( event.getServletContext());
Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out
of range: 11560 at
org.springframework.asm.ClassReader.readClass(Unknown Source) at
org.springframework.asm.ClassReader.accept(Unknown Source) at
org.springframework.asm.ClassReader.accept(Unknown Source) at
org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:59)
at
org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at
org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
at
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:237)

gatling jms-Nosuchmethoderror

I installed ActiveMQ in my local machine. I want to test it using Gatling. I created one simulation class to test my JMS. But I am getting error shown below.
Here is My Code:
import io.gatling.core.Predef._
import io.gatling.jms.Predef._
import scala.concurrent.duration._
import javax.jms._
import org.apache.activemq.ActiveMQConnectionFactory
class JmsTest extends Simulation{
val jmsConfig = jms
.connectionFactoryName("connectionFactory")
.url("tcp://localhost:61616")
.credentials("admin", "admin")
.contextFactory(classOf[org.apache.activemq.jndi.ActiveMQInitialContextFactory].getName)
.listenerCount(1)
val scn = scenario("JMS DSL test").repeat(1) {
exec(jms("req reply testing")
.reqreply
.queue("MyQueue")
.replyQueue("MyTopic")
.textMessage("Hello this is Naveen")
)
}
setUp(scn.inject(atOnceUsers(1)))
.protocols(jmsConfig)
}
I created jndi.properties file with following code.
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = vm://localhost
connectionFactoryNames = connectionFactory
queue.MyQueue = TestJms1
topic.MyTopic = TestJms1
The error which I am getting is:
Exception in thread "main" java.lang.NoSuchMethodError: io.gatling.jms.Predef$.jms()Lio/gatling/jms/protocol/JmsProtocolBuilderBase$;
at computerdatabase.JmsTest.<init>(JmsTest.scala:14)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at io.gatling.app.Gatling$.io$gatling$app$Gatling$$$anonfun$1(Gatling.scala:41)
at io.gatling.app.Gatling.run(Gatling.scala:92)
at io.gatling.app.Gatling.runIfNecessary(Gatling.scala:75)
at io.gatling.app.Gatling.start(Gatling.scala:65)
at io.gatling.app.Gatling$.start(Gatling.scala:57)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:49)
at io.gatling.app.Gatling$.main(Gatling.scala:43)
at io.gatling.app.Gatling.main(Gatling.scala)

Why the cryptic MultipleFailureException error message with the SpringJUnit4ClassRunner.withAfterClasses method

Why is my spring test set up failing with the following not-so-useful error messages below? All suggestions are appreciated.
JUnit Output
java.lang.NoClassDefFoundError: org/junit/runners/model/MultipleFailureException
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.withAfterClasses(SpringJUnit4ClassRunner.java:188)
at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:145)
at org.junit.runners.ParentRunner.run(ParentRunner.java:235)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run (SpringJUnit4ClassRunner.java:163)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: org.junit.runners.model.MultipleFailureException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 10 more
Console Output
INFO : org.springframework.test.context.support.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
INFO : org.springframework.test.context.support.DefaultTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
INFO : org.springframework.test.context.support.DefaultTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
INFO : org.springframework.test.context.support.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener#76959acc, org.springframework.test.context.support.DependencyInjectionTestExecutionListener#57e603e6, org.springframework.test.context.support.DirtiesContextTestExecutionListener#3e0a1e1f]
Here is the target snippet
#Service
public class PipApps {
#Resource( name = "apps" )
private Properties apps;
#Autowired
private SitePreferenceHandler sitePreferenceHandler;
#Autowired
private PipsTable pipsTable;
private SitePreference sitePreference;
private Device device;
public PipApps( HttpServletRequest request, HttpServletResponse response ){
sitePreference = sitePreferenceHandler.handleSitePreference( request, response );
device = DeviceUtils.getRequiredCurrentDevice( request );
}
public Properties getApps(){
return apps;
}
public Device getDevice(){
return device;
}
public SitePreference getSitePreference(){
return sitePreference;
}
public DeviceRouteTable getPipsTable(){
return pipsTable;
}
}
And the test snippet
#RunWith( SpringJUnit4ClassRunner.class )
#ContextConfiguration( locations={"src/test/resources/PipAppsTest-context.xml"} )
public class PipAppsTest {
#Mock
SitePreferenceHandler sitePreferenceHandler;
#Autowired
PipApps pipApps;
...
}
Update -- September 2015
Spring Framework 4.2.2 throws a more meaningful exception if JUnit 4.9 is not in the classpath. See SPR-13521 for details.
The following is an excerpt from the class-level Javadoc for SpringJUnit4ClassRunner:
NOTE: As of Spring Framework 4.1, this class requires JUnit 4.9 or higher.
The class in question, MultipleFailureException, was introduced in JUnit 4.9.
So that's why your test is failing with the ClassNotFoundException.
Upgrading to JUnit 4.9 (or preferably 4.12) will therefore solve your problem.
Regards,
Sam (author of the Spring TestContext Framework)

glassfish 4 EJB 3 standalone client jndi lookup

I have problem with calling remote ejb. I have successfully deployed remote EJB:
public interface IHelloWordlHome extends EJBHome {
mybeans.IHelloWordl create() throws RemoteException, javax.ejb.CreateException;
}
public interface IHelloWordl extends javax.ejb.EJBObject {
public String hello(String name) throws RemoteException;
}
#javax.ejb.Stateless(name = "HelloWordlEJB")
public class HelloWordlBean implements Serializable {
public HelloWordlBean() {
}
public String hello(String name) {
return "asd" + name;
}
public void ejbCreate() throws CreateException {
}
}
ejb-jar.xml:
<enterprise-beans>
<session>
<ejb-name>HelloWordlEJB</ejb-name>
<home>mybeans.IHelloWordlHome</home>
<remote>mybeans.IHelloWordl</remote>
<ejb-class>mybeans.HelloWordlBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
and now I am trying to run standalone client. That means it's totaly different application which now runs on same machine as server (localhost) but later it will run on different machine. As the glassfish description (dont have the link atm) says I used InitialContext without parameters, in server log I found the JNDI name of my bean ("java:global/ear_ear_exploded/ejb/HelloWordlEJB!mybeans.HelloWordlBean") and trying to look it up. I use gl-client.jar lib and I have it on my classpath. Note that I didnt copy that .jar, I am using the .jar in glassfish installation folder (I know that could be problem becouse it links other .jars) I copied (ctrl+c & ctrl+v) the bean interface (IHelloWordl) from server to client.
client code:
public static void main(String[] args) throws NamingException, RemoteException {
IHelloWordl foo = (IHelloWordl) new InitialContext().lookup("java:global/ear_ear_exploded/ejb/HelloWordlEJB!mybeans.HelloWordlBean");
foo.hello("Martin");
}
This is what my IDE runs:
P:\Java\jdk1.8.0\bin\java -Didea.launcher.port=7534 "-Didea.launcher.bin.path=P:\IntelliJ IDEA 13.1.1\bin" -Dfile.encoding=UTF-8 -classpath "P:\Java\jdk1.8.0\jre\lib\charsets.jar;P:\Java\jdk1.8.0\jre\lib\deploy.jar;P:\Java\jdk1.8.0\jre\lib\javaws.jar;P:\Java\jdk1.8.0\jre\lib\jce.jar;P:\Java\jdk1.8.0\jre\lib\jfr.jar;P:\Java\jdk1.8.0\jre\lib\jfxswt.jar;P:\Java\jdk1.8.0\jre\lib\jsse.jar;P:\Java\jdk1.8.0\jre\lib\management-agent.jar;P:\Java\jdk1.8.0\jre\lib\plugin.jar;P:\Java\jdk1.8.0\jre\lib\resources.jar;P:\Java\jdk1.8.0\jre\lib\rt.jar;P:\Java\jdk1.8.0\jre\lib\ext\access-bridge.jar;P:\Java\jdk1.8.0\jre\lib\ext\cldrdata.jar;P:\Java\jdk1.8.0\jre\lib\ext\dnsns.jar;P:\Java\jdk1.8.0\jre\lib\ext\jaccess.jar;P:\Java\jdk1.8.0\jre\lib\ext\jfxrt.jar;P:\Java\jdk1.8.0\jre\lib\ext\localedata.jar;P:\Java\jdk1.8.0\jre\lib\ext\nashorn.jar;P:\Java\jdk1.8.0\jre\lib\ext\sunec.jar;P:\Java\jdk1.8.0\jre\lib\ext\sunjce_provider.jar;P:\Java\jdk1.8.0\jre\lib\ext\sunmscapi.jar;P:\Java\jdk1.8.0\jre\lib\ext\sunpkcs11.jar;P:\Java\jdk1.8.0\jre\lib\ext\zipfs.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\out\production\project-ejbclient;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.annotation.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.ejb.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.jms.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.transaction.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.persistence.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.servlet.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.resource.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.servlet.jsp.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.servlet.jsp.jstl.jar;P:\glassfish4\glassfish\lib\gf-client.jar;P:\glassfish4\glassfish\lib\appserv-rt.jar;P:\IntelliJ IDEA 13.1.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain mybeans.Main
When I run the client I am getting exception which I can't realy understand and found no help online:
Exception in thread "main" javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.rmi.MarshalException: CORBA BAD_PARAM 1398079494 Maybe; nested exception is:
java.io.NotSerializableException: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM: WARNING: 00100006: Class mybeans.__EJB31_Generated__HelloWordlBean__Intf____Bean__ is not Serializable vmcid: SUN minor code: 6 completed: Maybe
at com.sun.proxy.$Proxy153.notSerializable(Unknown Source)
at com.sun.corba.ee.impl.misc.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:360)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:306)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeResult(DynamicMethodMarshallerImpl.java:488)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:177)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
----------END server-side stack trace----------]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:513)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at mybeans.Main.main(Main.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.rmi.MarshalException: CORBA BAD_PARAM 1398079494 Maybe; nested exception is:
java.io.NotSerializableException: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM: WARNING: 00100006: Class mybeans.__EJB31_Generated__HelloWordlBean__Intf____Bean__ is not Serializable vmcid: SUN minor code: 6 completed: Maybe
at com.sun.proxy.$Proxy153.notSerializable(Unknown Source)
at com.sun.corba.ee.impl.misc.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:360)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:306)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeResult(DynamicMethodMarshallerImpl.java:488)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:177)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
----------END server-side stack trace----------
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:300)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:211)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:150)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:226)
at com.sun.enterprise.naming.impl._SerialContextProvider_DynamicStub.lookup(com/sun/enterprise/naming/impl/_SerialContextProvider_DynamicStub.java)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:478)
... 8 more
Caused by: java.io.NotSerializableException: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM: WARNING: 00100006: Class mybeans.__EJB31_Generated__HelloWordlBean__Intf____Bean__ is not Serializable vmcid: SUN minor code: 6 completed: Maybe
at com.sun.proxy.$Proxy153.notSerializable(Unknown Source)
at com.sun.corba.ee.impl.misc.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:360)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:306)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeResult(DynamicMethodMarshallerImpl.java:488)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:177)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
----------END server-side stack trace----------
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:292)
... 13 more
Caused by: org.omg.CORBA.BAD_PARAM: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM: WARNING: 00100006: Class mybeans.__EJB31_Generated__HelloWordlBean__Intf____Bean__ is not Serializable vmcid: SUN minor code: 6 completed: Maybe
at com.sun.proxy.$Proxy153.notSerializable(Unknown Source)
at com.sun.corba.ee.impl.misc.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:360)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:306)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeResult(DynamicMethodMarshallerImpl.java:488)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:177)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
----------END server-side stack trace---------- vmcid: SUN minor code: 6 completed: Maybe
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.MessageBase.getSystemException(MessageBase.java:813)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:131)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.getSystemExceptionReply(MessageMediatorImpl.java:594)
at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.processResponse(ClientRequestDispatcherImpl.java:519)
at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.marshalingComplete(ClientRequestDispatcherImpl.java:393)
at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.invoke(ClientDelegateImpl.java:272)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:198)
... 12 more
I am despread :/ Can anyone help?
I'm not sure where you got this from but it looks like you mixed something up. In EJB 3 you don't have to extend EJBHome or EJBObject. You don't need the HomeInterface.
You should do it in this way:
import javax.ejb.Remote;
#Remote
public interface HelloWorldRemote {
public String hello(String name);
}
and:
#javax.ejb.Stateless(name = "HelloWorldEJB")
public class HelloWorldBean implements HelloWorldRemote {
public String hello(String name) {
return "asd" + name;
}
}
PS: There was a typo in your HelloWorld (HelloWordl).
You don't need any declaration in the ejb-jar.xml.
The client-code should look similar to this:
InitialContext con = new InitialContext();
HelloWorldBean foo = (HelloWorldBean) con.lookup("java:global/ear_ear_exploded/HelloWorldEJB");
See also:
EJB creating using SessionBean EJBObject and EJBHome interfaces
How to make EJB3 remote interface available to client?
EJB - Home/Remote and LocalHome/Local interfaces
Your class must be serializable, meaning your EJB needs implements Serializable

Spring 3.1 Java based configuration -- IllegalStateException

I am working my way through a Spring tutorial, I have the following code, using Java based configuration, that isn't working. In my classpath I have the Spring 3.1 jars, as well as asm-4.0.jar and cglib-2.2.2.jar.
MainApp.java:
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
public class MainApp {
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(
HelloWorldConfig.class);
HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
helloWorld.setMessage("Hello World!");
helloWorld.getMessage();
}
}
HelloWorldConfig.java:
package com.tutorialspoint;
import org.springframework.context.annotation.*;
#Configuration
public class HelloWorldConfig {
#Bean
public HelloWorld helloWorld() {
return new HelloWorld();
}
}
HelloWorld.java:
package com.tutorialspoint;
public class HelloWorld {
private String message;
public void setMessage(String message) {
this.message = message;
}
public void getMessage() {
System.out.println("Your Message : " + message);
}
}
Error code:
Exception in thread "main" java.lang.IllegalStateException: Cannot load configuration class: com.tutorialspoint.HelloWorldConfig
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:456)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigurationClasses(ConfigurationClassPostProcessor.java:202)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:176)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:604)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:437)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:68)
at com.tutorialspoint.MainApp.main(MainApp.java:8)
Caused by: java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method visit.(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at net.sf.cglib.core.AbstractClassGenerator.<init>(AbstractClassGenerator.java:38)
at net.sf.cglib.core.KeyFactory$Generator.<init>(KeyFactory.java:127)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:112)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:101)
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:89)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:448)
... 6 more
I changed the asm jar file from asm-4.0.jar to asm-3.3.jar, and it worked. There must have been a conflict between the first asm jar and the cglib jar I was using.
I was using cglib-2.1_3.jar and asm 3.1.jar when I ran in to this problem for the first time. After I removed the asm 3.1.jar and added asm- 1.5.3.jar it started working.
I was use cglib-2.1_3.jar and asm- 1.5.3, after using this jar my program run successfully.
ASM Core ยป 1.5.3
cglib-2.1_3.jar
Just adding this answer in case someone runs into the weird corner case issue I experienced.
This can also happen when the Jar file isn't properly signed.

Resources