I am using spring MVC for my project and in service classes i have used “@Autowired” annotations though i have to define all classes in bean tag in Application-Servlet.xml.(I feel its complicate if we have “N” number of classes) How i can avoid doing this?
Share
Its not clear which classes you are defining in XML config but I’ll take a guess that you’re asking about your service classes…
Simply annotate your service classes with
@Service(or@Component). The Spring docs will explain which to use and provides examples. Note: you’ll need to have these lines of XML config to make this work:<context:component-scan base-package="com.foo.bar"/>and<mvc:annotation-driven />Also works for controllers, simply annotate with
@Controller(docs).