does anyone know how to create object from mulitple data access object and call their method. When i create object from only one DAO and call their method then it works perfect but with multiple it throws null pointer exception,
and here's the error i am getting
java.lang.NullPointerException at front.Home.processRequest(Home.java:70) at front.Home.doGet(Home.java:97) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544) at java.lang.Thread.run(Thread.java:744)
Annotations are only applied to a single field, class or method, so you should annotate all your dependencies separately:
#EJB private CategoryDAO categoryDAO;
#EJB private GoldDAO goldDAO;
#EJB private ForexDAO forexDAO;
Related
Quarkus application (0.19.1), created from QuarkEE artifact fails to start with:
[io.qua.dev.DevModeMain] Failed to start quarkus: java.lang.ExceptionInInitializerError ..
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at io.quarkus.hibernate.validator.runtime.HibernateValidatorRecorder
EDIT
I've opened a ticket for it:
https://github.com/quarkusio/quarkus/issues/3284
Root cause was a bean validation constraint javax.validation.constraints.NotNull on the static factory method of the enum class. Simplified example:
public enum Gender {
MALE,
FEMALE;
public static Gender fromCode(#NotNull String code) {
return Gender.valueOf(code);
}
}
and having this dependency in your pom:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
Confusing thing is that static factory methods on simple POJO class works.
Note
I'm aware that validation of static methods is not supported by the Bean Validation specification. It is just a hint for IDE.
Java EE 8 Validating Constructors and Methods: Bean Validation constraints may be placed on the parameters of nonstatic methods and constructors and on the return values of nonstatic methods. Static methods and constructors will not be validated.
I am using SpringMockMvc and in my controller I have #ExceptionHandler. When calling post request, I am getting the below error.
Failed to invoke #ExceptionHandler method: public org.springframework.http.ResponseEntity<com.xx.xxx> com.xx.xx.handleException(java.lang.Throwable,org.eclipse.jetty.server.Request)
java.lang.IllegalStateException: Current request is not of type [org.eclipse.jetty.server.Request]: org.springframework.mock.web.MockHttpServletRequest#47fac1bd
at org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver.resolveArgument(ServletRequestMethodArgumentResolver.java:97)
I am not sure why #ExceptionHandler cannot handle if the request is of type org.springframework.mock.web.MockHttpServletRequest
That could never work, simply because org.springframework.mock.web.MockHttpServletRequest is not a sub-type of org.eclipse.jetty.server.Request. Thus, it is impossible for Spring to provide an instance of MockHttpServletRequest for a parameter of type org.eclipse.jetty.server.Request.
You'll need to change the type of the second parameter in your handleException() method to javax.servlet.http.HttpServletRequest.
I'm getting an ClassCastException while calling an EJB in an Pojo over JNDI. I use Oracle Weblogic Server 10.3.6 (EJB 3.0).
My structure:
app.ear
lib
Interfaces.jar
MyBeanInterface.java
ejb.jar
MyBeanImpl.java
webapp.war
Client.java
WEB-INF
web.xml
My local Interface:
package mypackage;
#Local
public Interface MyBeanInterface {}
My EJB-Class:
package mypackage;
#Stateless(name = "MyBean")
public class MyBeanImpl implements MyBeanInterface {}
My Client (not an EJB):
MyBeanInterface bean = (MyBeanInterface) new InitialContext().lookup("java:comp/env/ejb/MyBean");
My web.xml
<ejb-local-ref>
<ejb-ref-name>ejb/MyBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>mypackage.MyBeanInterface</local>
</ejb-local-ref>
My Exception:
The Lookup itself works. I get a reference. But when I want to cast with (MyBeanInterface) I get the following error:
Cannot cast an instance of "class mypackage.MyBeanInterface_whjkp6_MyBeanImpl (loaded by instance of weblogic.utils.classloaders.GenericClassLoader(id=28136))" to an instance of "interface mypackage.MyBeanInterface(loaded by instance of weblogic.utils.classloaders.GenericClassLoader(id=28144))
What can I do?
It seems the classes are loaded by different class loaders. Possible options are:
1) Ensure the classes are loaded by same class loader
2) Use reflection
3) Serialize and then deserialize
Refer:
1) cast across classloader?
2) https://community.oracle.com/thread/757133
3) ClassCastException because of classloaders?
Exception on Server
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'org.springframework.transaction.config.internalTransactionAdv
isor': Cannot resolve reference to bean 'org.springframework.transaction.annotat
ion.AnnotationTransactionAttributeSource#0' while setting bean property 'transac
tionAttributeSource'; nested exception is org.springframework.beans.factory.Bean
CreationException: Error creating bean with name 'org.springframework.transactio
n.annotation.AnnotationTransactionAttributeSource#0': Initialization of bean fai
led; nested exception is org.springframework.aop.framework.AopConfigException: C
ould not generate CGLIB subclass of class [class $Proxy73]: Common causes of thi
s problem include using a final class or a non-visible class; nested exception i
s java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy73
at org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveReference(BeanDefinitionValueResolver.java:329)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
an(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:198)
at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetriev
alHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:86)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyC
reator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:101)
at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAuto
ProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:8
5)
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProx
yCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.
postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:276)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFa
ctory.java:890)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:862)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:448)
... 63 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'org.springframework.transaction.annotation.AnnotationTransact
ionAttributeSource#0': Initialization of bean failed; nested exception is org.sp
ringframework.aop.framework.AopConfigException: Could not generate CGLIB subclas
s of class [class $Proxy73]: Common causes of this problem include using a final
class or a non-visible class; nested exception is java.lang.IllegalArgumentExce
ption: Cannot subclass final class class $Proxy73
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
an(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveReference(BeanDefinitionValueResolver.java:323)
... 80 more
Caused by: org.springframework.aop.framework.AopConfigException: Could not gener
ate CGLIB subclass of class [class $Proxy73]: Common causes of this problem incl
ude using a final class or a non-visible class; nested exception is java.lang.Il
legalArgumentException: Cannot subclass final class class $Proxy73
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProx
y.java:217)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.
java:111)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.
createProxy(AbstractAutoProxyCreator.java:477)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.
wrapIfNecessary(AbstractAutoProxyCreator.java:362)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.
postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFa
ctory.java:409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
... 86 more
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class
$Proxy73
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:
446)
at org.springframework.cglib.transform.TransformingClassGenerator.genera
teClass(TransformingClassGenerator.java:33)
at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(Defa
ultGeneratorStrategy.java:25)
at org.springframework.cglib.core.AbstractClassGenerator.create(Abstract
ClassGenerator.java:216)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:3
77)
at org.springframework.cglib.proxy.Enhancer.create(Enhancer.java:285)
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProx
y.java:205)
... 93 more
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.jav
a:1706)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:781)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleSta
teDriver.java:213)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleSta
teDriver.java:208)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineD
river.java:35)
Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalArgumentException: Cannot subclass final class class
$Proxy73
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:
446)
at org.springframework.cglib.transform.TransformingClassGenerator.genera
teClass(TransformingClassGenerator.java:33)
at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(Defa
ultGeneratorStrategy.java:25)
at org.springframework.cglib.core.AbstractClassGenerator.create(Abstract
ClassGenerator.java:216)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:3
Actually you should
not just post callstacks here but actually ask a question which can be answered by the community. Otherwise you keep us guessing what you might want to know.
read the exception before asking what it means because it clearly says so in this case.
search for similar problems here before posting.
Adding some line breaks into the relevant part of your call stack, it says:
org.springframework.aop.framework.AopConfigException:
Could not generate CGLIB subclass of class [class $Proxy73]:
Common causes of this problem include using a final class or
a non-visible class; nested exception is
java.lang.IllegalArgumentException:
Cannot subclass final class class $Proxy73
So obviously you are trying to weave code into a final class, which CGLIB is uncapable of (when used indirectly from Spring AOP). Probably your Spring configuration somehow indicates that proxies of proxies should be generated. Maybe SpringMVC Proxy issue helps you solve your problem. I am no Spring user, BTW. So if you cannot solve your problem by yourself with my hints, you need to edit the question and add more info to it, such as the aspect code, the Spring configuration and whatever else might be helpful.
I am using spring 3.0.6-RELEASE for a basic form based webapp and running into the following error on startup with PropertyPlaceHolderConfigurer. Not sure what's causing this as injecting the property pre-mvc3 was done through beans and now using annotation and it appears quite straight-forward atleast from the docs/other posts.
However the exception during tomcat server startup complains of org.springframework.core.ConstantException: Field 'SYSTEM_PROPERTIES_MODE_ENVIRONMENT' not found in class [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]
Here is what I have in spring-servlet.xml
<context:property-placeholder location="/WEB-INF/classes/spring.properties"/>
and my controller class
#Controller
#RequestMapping("/home")
public class HomeController {
// #Resource(name="broomManager")
#Autowired
private broomManager broomManager;
private #Value("${spring.broom.maxFileSize}") String inMemoryMaxFileSize;
private #Value("${spring.broom.fileDestination}") String destFilePath;
..
spring.properties
broom.maxFileSize=100000
broom.fileDestination=/Users/foobar/broom/files/
Exception during startup
2012-06-08 02:51:31,900 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'systemPropertiesModeName' threw exception; nested exception is org.springframework.core.ConstantException: Field 'SYSTEM_PROPERTIES_MODE_ENVIRONMENT' not found in class [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:626)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:467)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:483)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:358)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:325)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:831)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:720)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1217)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1306)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1570)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1579)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1559)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'systemPropertiesModeName' threw exception; nested exception is org.springframework.core.ConstantException: Field 'SYSTEM_PROPERTIES_MODE_ENVIRONMENT' not found in class [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
... 33 more
Probably the following is going on:
Your Spring config files are pointing at the 3.1 schemas.
You are using 3.0.6 JARs.
They need to match.