spring - @Service/@Controller annotations creates a new bean without using @Bean annotation -


i have class have annotated @service @scope

@slf4j @service @scope(value = "request", proxymode = scopedproxymode.target_class) public class productdatamodel { @value("${message}") private string message; 

the above code seems creating bean productdatamodel, without using @bean annotation.

i using @autowired productdatamodel productdatamodel in code, , dependency productdatamodel not null, when used above piece of code.

how come above code creating bean ??

ideally, have expected bean created when use below code

//i not using piece of code in program., reference  @configuration public class oscconfig {  @bean  @scope(value = "request", proxymode = scopedproxymode.target_class) productdatamodel productdatamodel(){ return new productdatamodel(); } 

can explain difference between 2 pieces of code , when use one.

the @service annotation picked spring when scanning objects create (as part of package scan). specialisation of spring @component annotation, doesn't add other providing indication users intended purpose. @controlller annotation similar, bean created has specific characteristics.

the @bean annotation have used used when creating objects, , in context on method in configuration class, therefore bean created of type returned method.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -