简体   繁体   English

删除Spring @controller注释并使用xml配置

[英]To remove off Spring @controller annotation and use xml configuration

I am using servlet with Spring as given below. 我在下面使用Spring的servlet。 This class also has a field which has been AutoWired . 此类还具有一个已自动接线的字段 I want to use xml configuration for this class and remove off annotation completely . 我想为此类使用xml配置并完全删除注释。 Please let me know how to do this 请让我知道该怎么做

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

HttpRequestHandler HttpRequestHandler

...... Web.xml configuration ...... Web.xml配置

<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. 为此,您需要在META-INF文件夹下放置一个application-context.xml,此外,您还需要使用标记在xml文件中定义bean,还需要使用构造函数注入或二传手注射。 and then you can use these beans. 然后您可以使用这些bean。

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的配置

XML Based Controller Configuration further more refer to spring documentation. 基于XML的控制器配置更多信息,请参见spring文档。 Also you need to include these configuration file in your web.xml as well. 另外,您还需要在web.xml中包括这些配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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