Hi,
I followed your instructions and it works!
For anyone interested my implementation of the config provider is:
@Override
public void register(ContainerBuilder builder, LocatableProperties props)
throws ConfigurationException {
builder.factory(Bean.class, new Factory<Bean>() {
@Override
public ContentXmlModel create(Context context) throws Exception {
return new Bean();
}
@Override
public Class<? extends Bean> type() {
return Bean.class;
}
}, Scope.SINGLETON);
}
So just register a new factory without invoking the method create on the
builder. You can ignore other overridden methods (loadPackages,destroy etc etc)
Thank you
Sent with Proton Mail secure email.
------- Original Message -------
On Wednesday, March 1st, 2023 at 8:27 AM, Lukasz Lenart
<[email protected]> wrote:
> sob., 25 lut 2023 o 12:47 Bogoljub Pavičić
> [email protected] napisał(a):
>
> > Hi,
> >
> > is it possible to produce beans using a factory method with struts2 default
> > ioc container?
> > I want to inject an ObjectMapper but I want to configure the bean before
> > inserting it in the container (similar to spring's @Bean method inside a
> > @Configuration class)
> >
> > @Bean
> > public ObjectMapper objectMapper() {
> >
> > return new ObjectMapper(new JavaTimeModule());
> >
> > }
>
>
> It's a bit more complicated in Struts, you must implement
> "ContainerProvider" or "ConfigurationProvider" interface, than
> register the provider:
> https://struts.apache.org/core-developers/configuration-provider-and-configuration
>
> then use register() to add your beans
> https://github.com/apache/struts/blob/master/core/src/main/java/com/opensymphony/xwork2/config/ContainerProvider.java#L58
>
> > the <bean> tag of struts.xml invokes only the empty constructor without
> > giving any arguments
>
>
> Not really, you can use @Inject to inject required dependencies
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]