Java equivalent of Spring XML configuration

I'm trying to figure out what the Java equivalent to this piece of Spring XML:

<bean id="foo" class="x.y.Foo">
    <property name="name" value="Rick"/>

Where value is an EncryptablePropertiesFactoryBean. I have it working with the XML configuration but I can't seem to find a Java alternative anywhere. Any assistance would be much appreciated.

1 answer

  • answered 2020-10-20 17:06 O. Azofeifa

    There are different ways to implement beans, I would suggest read this documentation for more comprenhention about how Spring uses beans:

    Spring IoC vs DI

    For the answer, a programatic way to do this could be:

    public class SomeConfiguration {
      public x.y.Foo foo(){
        // make something here
         EncryptablePropertiesFactoryBean Rick = new EncryptablePropertiesFactoryBean() // or any other instance of this
         return new x.y.Foo(Rick); //Where x.y.Foo has a property in its constructor of this type