I am not sure if I am allowed to ask more than one question in a post, but here it is,
For example I have the following,
Controllers
@Controller
public class FooController{
@Autowired
private FooService fooService;
@RequestMapping(value="/foo", method=RequestMethod.POST)
public @ResponseBody foo(@RequestBody FooRequest request){
}
}
@Controller
public class BarController{
@Autowired
private FooService fooService;
@RequestMapping(value="/bar", method=RequestMethod.POST)
public @ResponseBody bar(@RequestBody FooRequest request){
}
}
Service
public class FooService{
private Foo foo;
public Foo getFoo() {
return foo;
}
public void setFoo(Foo foo) {
this.foo = foo;
}
public String doFoo(String str){
return foo.doFoo(str);
}
}
class to do the job
public class Foo{
public String doFoo(String str){
return (str + " is foo");
}
}
create beans using dependency injection
<context:annotation-config/>
<bean id="fooService" class="com.myapp.service.FooService">
<property name="foo" ref="foo"></property>
</bean>
<bean id="foo" class="com.myapp.foo.Foo">
</bean>
My questions are:
- I did not use
@serviceannotation at classFooService, should I use it, and why? - Is this configuration thread-safe or not, and why (how is it achieved if it is thread-safe)?
- Where can I find a tutorial about the layers (dao layers, service layer …) used in Spring design and the purpose of such a design?
1 Answer