Failed to instantiate bean

I created a new managed bean and for some reason, it fails when starting the application server.
You can see the error message below. In CUBA Project Properties, I added my core dependencies:
myJARFiles:mina-core-1.1.0
myJARFiles-mina-core-1.1.0-sources
and i assembled the project.

In my code, it is failing at the following line:

acceptor = new SocketAcceptor
                    ( application, messageStoreFactory,
                            settings, logFactory, messageFactory );

would you know what I’m doing wrong?
thanks.


2016-04-26 10:47:13.517 WARN  [localhost-startStop-1] com.haulmont.cuba.core.sys.CubaCoreApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flux_FLUXimulator' defined in URL [jar:file:/C:/Users/Francis/studio-projects/flux-1.5/build/tomcat/webapps/flux-core/WEB-INF/lib/flux-core-0.1-SNAPSHOT.jar!/com/company/flux/core/FIX/FLUXimulator.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.company.flux.core.FIX.FLUXimulator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/mina/core/buffer/IoBufferAllocator
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) [spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93) [spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at com.haulmont.cuba.core.sys.CubaClassPathXmlApplicationContext.(CubaClassPathXmlApplicationContext.java:29) [cuba-global-6.1.2.jar:6.1.2]
 at com.haulmont.cuba.core.sys.CubaCoreApplicationContext.(CubaCoreApplicationContext.java:28) [cuba-core-6.1.2.jar:6.1.2]
 at com.haulmont.cuba.core.sys.AppContextLoader.createClassPathXmlApplicationContext(AppContextLoader.java:62) [cuba-core-6.1.2.jar:6.1.2]
 at com.haulmont.cuba.core.sys.AbstractAppContextLoader.initAppContext(AbstractAppContextLoader.java:53) [cuba-global-6.1.2.jar:6.1.2]
 at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:63) [cuba-global-6.1.2.jar:6.1.2]
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729) [catalina.jar:8.0.26]
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) [catalina.jar:8.0.26]
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.26]
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.26]
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.26]
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) [catalina.jar:8.0.26]
 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1101) [catalina.jar:8.0.26]
 at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1786) [catalina.jar:8.0.26]
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_65]
 at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_65]
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
 at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.company.flux.core.FIX.FLUXimulator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/mina/core/buffer/IoBufferAllocator
 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 ... 30 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/apache/mina/core/buffer/IoBufferAllocator
 at com.company.flux.core.FIX.FLUXimulator.(FLUXimulator.java:92) ~[flux-core-0.1-SNAPSHOT.jar:na]
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_65]
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_65]
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_65]
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_65]
 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 ... 32 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.mina.core.buffer.IoBufferAllocator
 at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_65]
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_65]
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_65]
 ... 38 common frames omitted
2016-04-26 10:47:13.640 INFO  [localhost-startStop-1] com.haulmont.cuba.core.sys.CubaThreadPoolTaskScheduler - Shutting down ExecutorService 'scheduler'
2016-04-26 10:47:13.670 WARN  [localhost-startStop-1] eclipselink.connection - 
2016-04-26 10:47:13.723 ERROR [localhost-startStop-1] com.haulmont.cuba.core.sys.AppContextLoader - Error initializing application
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flux_FLUXimulator' defined in URL [jar:file:/C:/Users/Francis/studio-projects/flux-1.5/build/tomcat/webapps/flux-core/WEB-INF/lib/flux-core-0.1-SNAPSHOT.jar!/com/company/flux/core/FIX/FLUXimulator.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.company.flux.core.FIX.FLUXimulator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/mina/core/buffer/IoBufferAllocator
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at com.haulmont.cuba.core.sys.CubaClassPathXmlApplicationContext.(CubaClassPathXmlApplicationContext.java:29) ~[cuba-global-6.1.2.jar:6.1.2]
 at com.haulmont.cuba.core.sys.CubaCoreApplicationContext.(CubaCoreApplicationContext.java:28) ~[cuba-core-6.1.2.jar:6.1.2]
 at com.haulmont.cuba.core.sys.AppContextLoader.createClassPathXmlApplicationContext(AppContextLoader.java:62) ~[cuba-core-6.1.2.jar:6.1.2]
 at com.haulmont.cuba.core.sys.AbstractAppContextLoader.initAppContext(AbstractAppContextLoader.java:53) ~[cuba-global-6.1.2.jar:6.1.2]
 at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:63) ~[cuba-global-6.1.2.jar:6.1.2]
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729) [catalina.jar:8.0.26]
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) [catalina.jar:8.0.26]
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.26]
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.26]
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.26]
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) [catalina.jar:8.0.26]
 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1101) [catalina.jar:8.0.26]
 at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1786) [catalina.jar:8.0.26]
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_65]
 at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_65]
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
 at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.company.flux.core.FIX.FLUXimulator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/mina/core/buffer/IoBufferAllocator
 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 ... 30 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/apache/mina/core/buffer/IoBufferAllocator
 at com.company.flux.core.FIX.FLUXimulator.(FLUXimulator.java:92) ~[flux-core-0.1-SNAPSHOT.jar:na]
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_65]
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_65]
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_65]
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_65]
 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
 ... 32 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.mina.core.buffer.IoBufferAllocator
 at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_65]
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_65]
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_65]
 ... 38 common frames omitted

Hi Francis,
As I understand, you are trying to use JAR files from a local directory. Studio currently does not support this, it can only use dependencies from remote repositories.
So you have to edit build.gradle manually and add your libraries to the flatDir section.

Hello, here’s attached my build.gradle file. Also, in my flatdir directory, all the libraries are there already.

build.zip (2.4K)

Caused by: java.lang.ClassNotFoundException: org.apache.mina.core.buffer.IoBufferAllocator

I guess the jar file is not found.

Try to do it like this.

  • In Studio, go to Project Properties > Edit > Advanced

  • Add compile dependency for “core” module and specify its coordinates, like “activemq:activemq-client:5.13.0”

  • After saving changes, Gradle will recompile the project and recreate IntelliJ files.

If you have a standalone JAR, you have to add a file-based repository to build.gradle manually, for example:

buildscript {

repositories {

maven {

}

flatDir { dirs ‘c:\work\lib’ }

}

After that, place your JAR into this directory and specify the dependency as described above. The coordinates must contain at least two parts: “mylibrary:myfile”, where “mylibrary” is an arbitrary group (it is ignored) and “myfile” - name of the JAR file (myfile.jar)

Remember that don’t use .jar in (“mylibrary:myfile”) in studio. Then it build like a charm.

I have tried it with Notes.jar and it worked like a charm.

Thanks for the details. This is exactly what I have done but I’m still getting the same error message.

Have you checked that the jar archive is compatible with Java 1.8.
Can you share the source and jar archive.
I want to test it on my system.

1 Like
  • Try to remove mina-core-1.1.0-sources from the dependencies. Not sure this is the cause, but the sources JAR is not needed anyway - it will be automatically picked up and added to the IDE project files if present.
  • Ensure that mina-core-1.1.0.jar is copied to tomcat/shared/lib on deployment
  • Ensure that mina-core-1.1.0.jar really contains the org/apache/mina/core/buffer/IoBufferAllocator.class file

Please ignore this, see Kjell’s comment below.

Thanks for the suggestions. I was able to solve the issue with your help. I basically removed all the mina jars, downloaded the latest version mina-core.2.0.4 and installed it and everything worked. Thanks for your help.

1 Like