简体   繁体   中英

To remove off Spring @controller annotation and use xml configuration

I am using servlet with Spring as given below. This class also has a field which has been AutoWired . I want to use xml configuration for this class and remove off annotation completely . Please let me know how to do this

@Controller("oauth2Servlet")
final public class Oauth2Servlet extends HttpServlet implements

HttpRequestHandler

...... Web.xml configuration

<servlet>
<display-name>Oauth2Servlet</display-name>
<servlet-name>oauth2Servlet</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>oauth2Servlet</servlet-name>
<url-pattern>/oauth2</url-pattern>
</servlet-mapping>

to do this you need to have a application-context.xml in place under the META-INF folder, apart from this you need to define your beans in xml file using tag, you need to inject your dependency in beans using either constructor injection or setter injection. and then you can use these beans.

I would suggest you to keep it annotation based its more readability while using annotation, You can find xml based configuration here in this example

XML Based Controller Configuration further more refer to spring documentation. Also you need to include these configuration file in your web.xml as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM