I\'m curious to know what\'s the difference between code like this:
class MyClass {
@Autowired
MyService myService;
}
and code like t
@watchme @Required -annotation tells to the container that this property needs to be initialized as part of configuration, it can be initialized either through xml configuration or through @Autowired annotation or through java bean creation.
xml example:
public class SimpleMovieLister
{
private MovieFinder movieFinder;
@Required
public void setMovieFinder(MovieFinder movieFinder)
{
this.movieFinder = movieFinder;
}
}
through @Autowire
public class SimpleMovieLister
{
@Autowired
@Required
private MovieFinder movieFinder;
}
Here truly speaking we don't need @Required as it @Autowired default is Required.
thru @Bean
public class SimpleMovieLister
{
private MovieFinder movieFinder;
@Required
public void setMovieFinder(MovieFinder movieFinder)
{
this.movieFinder = movieFinder;
}
}
public class AppConfig {
@Bean
public SimpleMovieLister getSimpleMovieLister()
{
SimpleMovieLister simpleMovieLister = new SimpleMovieLister();
simpleMovieLister.setMovieFinder(new MoveFinder());
}
}