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 securityconfig
class. 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.
Source: stackoverflow.com
Related Query
- How to implement Spring Security 4 with both XML and Java config
- How can I run both xml config driven and xml-less Spring webapps together with Maven?
- how to specify spring java config and xml config both in spring contextConfigLocation in web.xml
- How to implement Spring Security with LDAP and Role based granted authorities from database?
- Using Java config with Spring Security for annotation-based role checks and Basic HTTP Auth
- Spring Security login with UserDetailsService and Java config
- How to authenticate user with LDAP using xml config file ,JAVA, Spring security
- Spring 4 + Sitemesh with Java Config and no xml
- How to stick with both XML and Annotation based configuration Spring
- How to configure Spring Security with Hibernate and XML
- how to test DAO Implementations methods in spring mvc with java configuration classes and no XML using jUnit
- Integrate XML based spring mvc with java config based spring security
- How to Configure spring mvc 4 with hibernate and Jpa using java config
- Custom Authentication Manager with Spring Security and Java Configuration
- How to implement login page using Spring Security so that it works with Spring web flow?
- Security Method Annotations with Java Configuration and Spring Security 3.2
- How to enable HTTP caching for the resource handler with Spring MVC and Spring Security
- Spring REST with both JSON and XML
- How implement Spring security when login page having more field apart from user name and password?
- How to handle 404 page not found exception in Spring MVC with java configuration and no Web.xml
- How to inject session scope bean in interceptor using java config with Spring
- Spring Security 3.2: @Autowire doesn't work with java configuration and custom AuthenticationProvider in Spring MVC application?
- How to implement Dart with Spring MVC and Thymeleaf?
- Spring root and servlet context with Java config
- How to get same session with Spring Security and Spring Session From multiple server
- Using both LDAP and DB authentication with Spring Security
- How to configure Spring Boot and Spring Security to support both form login and Google OAuth2 login
- How to perform RunAs using method security with Spring MVC 3.2 and Spring Security 3.1
- How to authenticate a user via Spring Security and MarkLogic's Java Client API?
- spring security with java config , No bean named 'springSecurityFilterChain' is defined error
More Query from same tag
- access specific URL for specific user in spring security
- Spring MVC: One View - Multiply Controllers
- How to send values and image form javascript to controller in spring MVC
- Spring MVC Controller common logic
- Dependent dropdown using json, html and jQuery
- Integration of Spring MVC with Hibernate using Maven
- Problem uploading a file with ajax in appengine
- import Date from database into an excel sheet
- Spring Security 3.2.1 Multiple login forms with distinct WebSecurityConfigurerAdapters
- Spring Boot Application add datasource at runtime?
- How is autowired deciding which context/configuration file to use
- Generated download file contains html
- Returning an empty "content" array when the page has no elements
- Spring 3 mvc and tiles - populate *.jsp page with some data before
- Spring MVC + EntityManger - Error creating bean
- jquery parse spring mvc object auto call toString
- dropdown lists with Thymeleaf and SpringBoot
- SimpleJdbcCall executeObject() usage in Spring Framework
- I have a string : "14 Feb 2012" that I want to deserialize to a joda-time LocalDate via spring/json/jackson
- Spring data jpa repository find by multi elements
- Getting Error While deploying Spring application on Wildfly16 (Migrating from Wildfly8 to 16)
- Clean up user input from unwanted HTML in a Spring web application
- How are beans correctly used and what do they represent?
- Unable to autowire SessionFactory in My DAO Class
- How do I prevent Spring 4.0 MVC @ModelAttribute variables from appearing in URL?
- Iterator - java.util.NoSuchElementException in Spring MVC Controller
- Spring MVC: Unable to access HTML page via InternalResourceViewResolver
- How can Spring RestController accept both JSON and XML?
- HTTP Status 400 - Required String parameter 'xx' is not present
- AuditingEntityListener is not working for the entity that extends another abstract entity in spring jpa