score:0

add the following line in your spring-context.xml:

<!-- to activate annotations in beans already registered in the application context -->
<context:annotation-config />

and then can add the bean definition for the security config.

<bean name="securityconfig" class="com.config.security.securityconfig" />

score:2

assuming what you want is to get spring security java config working with only 2 classes securityconfig and securitywebapplicationinitializer, you need to do the following to get it working. please note that i am assuming that your spring mvc configuration is still xml. please note that com.mkyong.web.config package will have the securityconfigclass. this will ensure that the web context will have your security configuration available.

web.xml as follows

<context-param>
          <param-name>contextclass</param-name>
          <param-value>
              org.springframework.web.context.support.annotationconfigwebapplicationcontext
          </param-value>
      </context-param>
      <context-param>
          <param-name>contextconfiglocation</param-name>
          <param-value>com.mkyong.web.config</param-value>
      </context-param>

   <listener>
      <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>
  </listener>

score:3

thanks to arunm, i revisited my issue and now have an xml and java config combination. spring mvc and the web app does use web.xml and default-servlet.xml plus a java config app class that imports spring security.

@configuration
@import({ securityconfig.class})
@importresource( {"classpath:web-context.xml",
   "classpath:service-context.xml","classpath:data-context.xml"})
public class appconfig {
   public appconfig() {
      super();
   }
}

i use the @import annotation to import the spring security securityconfig class.

i also do my contextconfiglocation scanning for all my context files via annotation: @importresource.

the trick was not to load securityconfig via the contextconfiglocation but create an appconfig class that sets up the app context by including everything in it together.


Related Query

More Query from same tag