0

ページで次のコードを使用した場合、Illegalstate 例外は発生しませんでした。

ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
 StudentService studentService = context.getBean(StudentService.class); 

私が使用した場合

@SpringBean
private StudentService studentService;

次の例外が発生しました

  java.lang.IllegalStateException: bean of type [org.jeyam.samson.consumer.service.StudentService] not found
    at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanNameOfClass(AnnotProxyFieldValueFactory.java:236)
    at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanName(AnnotProxyFieldValueFactory.java:179)
    at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:113)
    at org.apache.wicket.injection.Injector.inject(Injector.java:111)
    at org.apache.wicket.spring.injection.annot.SpringComponentInjector.inject(SpringComponentInjector.java:124)
    at org.apache.wicket.spring.injection.annot.SpringComponentInjector.onInstantiation(SpringComponentInjector.java:130)
    at org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:38)
    at org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:34)
    at org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection.java:80)
    at org.apache.wicket.application.ComponentInstantiationListenerCollection.onInstantiation(ComponentInstantiationListenerCollection.java:33)
    at org.apache.wicket.Component.<init>(Component.java:683)
    at org.apache.wicket.MarkupContainer.<init>(MarkupContainer.java:121)
    at org.apache.wicket.Page.<init>(Page.java:168)
    at org.apache.wicket.Page.<init>(Page.java:157)
    at org.apache.wicket.markup.html.WebPage.<init>(WebPage.java:106)
    at org.jeyam.samson.consumer.page.HomePage.<init>(HomePage.java:28)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:171)
    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:76)
    at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133)
    at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:268)
    at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
    at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78)
    at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:269)
    at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165)
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
    at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1332)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:477)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1031)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:965)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
    at org.eclipse.jetty.server.Server.handle(Server.java:348)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:452)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:884)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:938)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
    at java.lang.Thread.run(Thread.java:724)

    Complete stack:

    org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public org.jeyam.samson.consumer.page.HomePage(org.apache.wicket.request.mapper.parameter.PageParameters)' and argument ''. An exception has been thrown during construction!
    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:194)
    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:76)
    at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133)
    at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:268)
    at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
    at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78)
    at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:269)
    at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165)
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
    at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)

    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:171)
    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:76)
    at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133)
    at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:268)
    at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
    at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78)
    at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:269)
    at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165)
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
    at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)

Web アプリで次の依存関係を使用しています。

wicket = wickte-core、wicket-ioc、および wicket-spring の場合 (バージョン 6.10.0)

spring = spring-data-mongodb(1.2.1-RELEASE)、spring-web および spring-context-support(3.1.4-RELEASE) の場合

javax.inject(バージョン-1)

Student service class 

@Repository
@Named
public class StudentService 
{
create(Student student)
{
....
}
}

アプリケーション context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

        <!-- Activate annotation configured components -->
        <context:annotation-config/>

        <!-- Scan components for annotations within the configured package -->
        <context:component-scan base-package="org.jeyam.samson.consumer">
            <context:exclude-filter type="annotation" expression="org.springframework.context.annotation.Configuration"/>
        </context:component-scan>

 ....
</beans>

WicketApplication.java

init()
{
.....
getComponentInstantiationListeners().add(new SpringComponentInjector(this, getSpringContext()));

}

public ApplicationContext getSpringContext()
{
  return WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
}

Web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <display-name>myapp</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
.......
......
</web-app>

サービス クラスから @Named アノテーションを削除しました。@SpringBean の代わりに @Autowired を使用しました。NullPointerException を取得しました

java.lang.NullPointerException
at org.jeyam.samson.consumer.page.HomePage$1.onSubmit(HomePage.java:64)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1253)
at org.apache.wicket.markup.html.form.Form.process(Form.java:925)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:771)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:704)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:240)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:226)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1332)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:477)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1031)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:965)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
at org.eclipse.jetty.server.Server.handle(Server.java:348)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:452)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:894)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:948)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:851)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
at java.lang.Thread.run(Thread.java:724)

Complete stack:

org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at [Form [Component id = form]] on component [Form [Component id = form]] threw an exception
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:268)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:240)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:226)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:240)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:226)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
4

4 に答える 4

0

最初のケースが機能するのは奇妙です。Java EE アノテーションの実装であるアノテーションを使用して@Namedいます (Spring はまだサポートしていません)。@Named注釈を削除します。@Repository春の注釈です。また@SpringBean@Autowired

于 2013-09-29T11:17:21.970 に答える
0

applicationContext.xml に以下を追加してみてください

<bean id="StudentService" class="org.jeyam.samson.consumer.service.StudentService">
于 2013-09-29T11:14:20.030 に答える
0

パッケージ org.springframework.stereotype.Service の StudentServiceImple に @Service を宣言する

于 2019-03-15T07:39:57.537 に答える