Beans - AlexGPlay/Blynder GitHub Wiki

What is a Bean

A bean is a class that holds some code that can be reutilized. In Blynder all the base components are beans and it means that the instantation of the object is automatic.

How to use

You can create your own Beans by just using the @Bean annotation.

@Bean
public class FooBean{
...
}

This notation will make the class a Bean and that will allow the class to be autowired. Autowiring a class means that its instance will be automaticly created. In order to make the framework know it has to autowire the class when you want you have to use the @Autowired annotation.

@Bean
public class AnotherBean{

  @Autowired
  private FooBean bean;

}

As you can see in the example, the bean field is annotated with autowired, so the bean will have an instance when used. There is an important restriction to this, you can only autowire a field in another bean class. You can use the @Autowired annotation wherever you want but it won't work if it isn't inside another bean. The example given before works fine, but this one won't work:

public class FooClass{

  @Autowired
  private FooBean bean;

}