Re: @SpringBean injection problem
Cemal -- Thanks, the trace indeed looks familiar. I will try the suggestion to make Bean2 an interface. I will also try to distill a test from this problem. Will let you know. Thanks, -- Sasha jWeekend wrote: Sasha, Does the trace at the end of this note, in my PS, look familiar? Now try the following code (notice the addition and use of the IBean2 interface) - things should work once you make the type of the reference in your component (a Page in this case) the interface. If you can't do that on your project (eg Bean2 is from a 3rd party library) then we'll have to take another look. Does that help? === public class SpringBeanPage extends WebPage{ @SpringBean IBean2 bean2; public SpringBeanPage() { add(new Label("sprung",bean2.getBean1().name)); } } public class Bean1 { public String name; @Override public String toString() { return name; } } === public class Bean2 implements IBean2 { public Bean1 bean1; protected Bean2(Bean1 bean1) { super(); this.bean1 = bean1; bean1.name = "Sprung"; } public Bean1 getBean1() { return bean1; } public void setBean1(Bean1 bean1) { this.bean1 = bean1; } } Regards - Cemal http://www.jWeekend.co.uk http://jWeekend.co.uk PS Is this similar to the exception you saw? org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor public scratch.springbean.SpringBeanPage() at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:168) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:58) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:262) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:283) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:210) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:149) ... 29 more Caused by: java.lang.RuntimeException: error while injecting object [[Page class = scratch.springbean.SpringBeanPage, id = 0, version = 0]] of type [scratch.springbean.SpringBeanPage] at org.apache.wicket.injection.Injector.inject(Injector.jav
Re: @SpringBean injection problem
this isnt really wicket-specific. this is just something you need to be aware of when dealing with IOC containers. if you wanted to eg have transactional methods on this bean you would run into the same problem as spring would try to create a proxy of your class to manage transactions (unless you were using direct bytecode weaving...) -igor On Sun, Aug 31, 2008 at 6:45 PM, Sasha Ovsankin <[EMAIL PROTECTED]> wrote: > Cemal -- > > Thanks, the trace indeed looks familiar. I will try the suggestion to make > Bean2 an interface. I will also try to distill a test from this problem. > > Will let you know. > > Thanks, > -- Sasha > > jWeekend wrote: >> >> Sasha, >> >> Does the trace at the end of this note, in my PS, look familiar? >> Now try the following code (notice the addition and use of the IBean2 >> interface) - things should work once you make the type of the reference in >> your component (a Page in this case) the interface. If you can't do that >> on >> your project (eg Bean2 is from a 3rd party library) then we'll have to >> take >> another look. >> Does that help? >> >> >>> ref="bean1"/> >> === >> public class SpringBeanPage extends WebPage{ >>@SpringBean IBean2 bean2; >>public SpringBeanPage() { >>add(new Label("sprung",bean2.getBean1().name)); >>} } >> >> public class Bean1 { >>public String name; >>@Override >>public String toString() { >>return name; >>} >> } >> === >> public class Bean2 implements IBean2 { >>public Bean1 bean1; >>protected Bean2(Bean1 bean1) { >>super(); >>this.bean1 = bean1; >>bean1.name = "Sprung"; >>} >>public Bean1 getBean1() { >>return bean1; >>} >>public void setBean1(Bean1 bean1) { >>this.bean1 = bean1; >>} >> } >> >> Regards - Cemal >> http://www.jWeekend.co.uk http://jWeekend.co.uk >> PS Is this similar to the exception you saw? >> org.apache.wicket.WicketRuntimeException: Can't instantiate page using >> constructor public scratch.springbean.SpringBeanPage() >>at >> >> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:168) >>at >> >> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:58) >>at >> >> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:262) >>at >> >> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:283) >>at >> >> org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:210) >>at >> >> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) >>at >> >> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166) >>at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243) >>at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331) >>at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) >>at >> org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363) >>at >> >> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194) >>at >> >> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) >>at >> >> org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112) >>at >> >> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) >>at >> >> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) >>at >> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) >>at >> >> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) >>at >> org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) >>at >> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) >>at >> org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) >>at >> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139) >>at org.mortbay.jetty.Server.handle(Server.java:324) >>at >> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) >>at >> >> org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828) >>at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) >>at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) >>at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) >>at >> >> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) >>at >> >> org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450
Re: @SpringBean injection problem went away
Igor and all -- I also had this problem when using default constructor and initialization by properties. OTOH I have Hibernate DAO classes using transactions, and they work fine. Good news, the problem went away when I broke the Bean1->Bean2 chain because of application reasons. If/when the problem reappears, I will try to report in more detail. Thanks everyone for your help, -- Sasha Igor Vaynberg wrote: this isnt really wicket-specific. this is just something you need to be aware of when dealing with IOC containers. if you wanted to eg have transactional methods on this bean you would run into the same problem as spring would try to create a proxy of your class to manage transactions (unless you were using direct bytecode weaving...) -igor On Sun, Aug 31, 2008 at 6:45 PM, Sasha Ovsankin <[EMAIL PROTECTED]> wrote: Cemal -- Thanks, the trace indeed looks familiar. I will try the suggestion to make Bean2 an interface. I will also try to distill a test from this problem. Will let you know. Thanks, -- Sasha jWeekend wrote: Sasha, Does the trace at the end of this note, in my PS, look familiar? Now try the following code (notice the addition and use of the IBean2 interface) - things should work once you make the type of the reference in your component (a Page in this case) the interface. If you can't do that on your project (eg Bean2 is from a 3rd party library) then we'll have to take another look. Does that help? === public class SpringBeanPage extends WebPage{ @SpringBean IBean2 bean2; public SpringBeanPage() { add(new Label("sprung",bean2.getBean1().name)); } } public class Bean1 { public String name; @Override public String toString() { return name; } } === public class Bean2 implements IBean2 { public Bean1 bean1; protected Bean2(Bean1 bean1) { super(); this.bean1 = bean1; bean1.name = "Sprung"; } public Bean1 getBean1() { return bean1; } public void setBean1(Bean1 bean1) { this.bean1 = bean1; } } Regards - Cemal http://www.jWeekend.co.uk http://jWeekend.co.uk PS Is this similar to the exception you saw? org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor public scratch.springbean.SpringBeanPage() at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:168) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:58) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:262) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:283) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:210) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) at org.mortbay.thread.Bounded