0

This question is about Java config in Spring. Is it possible to replace the following declaration in Java code.

<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/secure-app-context.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Where secure-app-context.xml

  <beans xmlns="http://www.springframework.org/schema/beans"
    ...
    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

    <aop:aspectj-autoproxy />

    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="false">
        <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
            </mvc:message-converters>
        </mvc:annotation-driven> 

        <context:component-scan base-package="com.abc.secure.service" />

        <bean id="securityAspect" class="com.abc.secure.service.Secure" />
    </beans>
user2498899
  • 153
  • 8

1 Answers1

0

You can very well do it by using WebApplicationInitializer(you dont need web.xml in this case)

Please see the post below:

How to configure Spring MVC with pure Java-based configuration?

Community
  • 1
  • 1
shankarsh15
  • 1,947
  • 1
  • 11
  • 16