I have rest style controller in Spring. In controller I have injected dao interfaces. From controller I persist data. In the other words, I have like REST web service. people sends me data, and I persits it.
/**
* Payment rest controller which receives
* JSON of data
*/
@Controller
@RequestMapping("/data")
public class PaymentTransaction {
@Autowired
private TestDao dao;
@RequestMapping(value = "/test", method = RequestMethod.POST)
@ResponseBody()
public String test(HttpServletRequest request) {
...
}
At the moment I have @transaction annotation in Dao classes. For instance:
import org.springframework.transaction.annotation.Transactional;
@Component
@Transactional
public interface TestDao {
@Transactional(propagation = Propagation.REQUIRED)
public void first();
}
I have read that this is very bad style. Using this answer at stackoverflow , here is explain and examples why is this bad - we must not add this annotation in DAO and in controller too. We must add it in service layer.
But I don't understand what is the service layer? Or where is it? I do not have anything like this. where should I write @Transactional annotation?
Best regards,