Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concrete bean could not be received from the application context #57

Open
stefv opened this issue Nov 11, 2020 · 1 comment
Open

Concrete bean could not be received from the application context #57

stefv opened this issue Nov 11, 2020 · 1 comment

Comments

@stefv
Copy link

stefv commented Nov 11, 2020

Hello,

I'm making a spring boot application using Wicket and PF4J. I want to use spring services in my plugins. These services are not using services outside the plugin class loader. In my plugin, I can have wicket panels. The panel class can use the Spring service.

Here the class of the plugin:

public class MyPlugin extends SpringPlugin implements MyPluginConfiguration {

	public MyPlugin(PluginWrapper wrapper) {
		super(wrapper);
	}

	@Override
	protected ApplicationContext createApplicationContext() {
		final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
		applicationContext.setClassLoader(getWrapper().getPluginClassLoader());
		applicationContext.register(SpringConfiguration.class);
		applicationContext.refresh();
		return applicationContext;
	}

	@Override
	public Panel getConfigurationPanel(String wicketId) {
		return new ConfigurationPanel(wicketId);
	}

}

Its interface:

public interface MyPluginConfiguration {

	Panel getConfigurationPanel(String wicketId);
}

The SpringConfiguration class:

@Configuration
public class SpringConfiguration {

	@Bean
	public LabelService getLabelService() {
		return new LabelService();
	}
}

The configuration panel:

public class ConfigurationPanel extends Panel {

	@SpringBean
	private LabelService labelService;

	public ConfigurationPanel(String id) {
		super(id);

		add(new Label("text", labelService.getLabel()));
	}

}

And the service:

@Service
public class LabelService {

	public String getLabel() {
		return "Hello World from the plugin.";
	}
}

To display the configuration, i'm using this page in my application:

public class PluginTestPage extends WebPage {

	@SpringBean
	private PluginManager pluginManager;

	public PluginTestPage() {
		final PluginWrapper pluginWrapper = pluginManager.getPlugin("example");
		if (pluginWrapper.getPlugin() instanceof MyPluginConfiguration) {
			final MyPluginConfiguration pluginConfiguration = (MyPluginConfiguration) pluginWrapper.getPlugin();
			add(pluginConfiguration.getConfigurationPanel("configuration-panel"));
		} else {
			add(new Label("configuration-panel", "Can't get the configuration panel"));
		}
	}

}

When I'm asking the PluginTestPage, I have this error:

org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public com.example.pages.PluginTestPage()'. An exception has been thrown during construction!
	at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:194) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:67) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:90) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.core.request.handler.PageProvider$Provision.getPage(PageProvider.java:369) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:170) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:231) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:202) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:917) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.request.RequestHandlerExecutor.execute(RequestHandlerExecutor.java:63) ~[wicket-request-9.0.0.jar:9.0.0]
	at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:283) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:254) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:222) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:276) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:207) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:300) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: java.lang.reflect.InvocationTargetException: null
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
	at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:175) ~[wicket-core-9.0.0.jar:9.0.0]
	... 33 common frames omitted
Caused by: java.lang.IllegalStateException: Concrete bean could not be received from the application context for class: com.example.pf4j_wicket_spring.services.LabelService.
	at org.apache.wicket.spring.SpringBeanLocator.lookupSpringBean(SpringBeanLocator.java:277) ~[wicket-spring-9.0.0.jar:9.0.0]
	at org.apache.wicket.spring.SpringBeanLocator.locateProxyTarget(SpringBeanLocator.java:198) ~[wicket-spring-9.0.0.jar:9.0.0]
	at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:150) ~[wicket-spring-9.0.0.jar:9.0.0]
	at org.apache.wicket.injection.Injector.inject(Injector.java:111) ~[wicket-ioc-9.0.0.jar:9.0.0]
	at org.apache.wicket.spring.injection.annot.SpringComponentInjector.inject(SpringComponentInjector.java:124) ~[wicket-spring-9.0.0.jar:9.0.0]
	at org.apache.wicket.spring.injection.annot.SpringComponentInjector.onInstantiation(SpringComponentInjector.java:130) ~[wicket-spring-9.0.0.jar:9.0.0]
	at org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:38) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:34) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection.java:80) ~[wicket-util-9.0.0.jar:9.0.0]
	at org.apache.wicket.application.ComponentInstantiationListenerCollection.onInstantiation(ComponentInstantiationListenerCollection.java:33) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.Component.<init>(Component.java:682) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.MarkupContainer.<init>(MarkupContainer.java:185) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.markup.html.WebMarkupContainer.<init>(WebMarkupContainer.java:53) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.markup.html.WebMarkupContainer.<init>(WebMarkupContainer.java:45) ~[wicket-core-9.0.0.jar:9.0.0]
	at org.apache.wicket.markup.html.panel.Panel.<init>(Panel.java:67) ~[wicket-core-9.0.0.jar:9.0.0]
	at com.example.pf4j_wicket_spring.panels.ConfigurationPanel.<init>(ConfigurationPanel.java:25) ~[na:na]
	at com.example.pf4j_wicket_spring.MyPlugin.getConfigurationPanel(MyPlugin.java:40) ~[na:na]
	at com.example.pages.PluginTestPage.<init>(PluginTestPage.java:30) ~[classes/:na]
	... 38 common frames omitted

Is it a mistake with my settings ?

Regards,
Stef

@decebals
Copy link
Member

Please take a look at pf4j-wicket. Maybe you can match pf4j-spring with pf4j-wicket.
By the way, I used Wicket in the past with a real success and pleasure. It's a nice web framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants