出于某种原因(我真的不能rembember为什么:))我决定只使用Java来配置Spring应用程序。此外,我会尽量避免web.xml弹簧安全的春天Java配置
我开始与follinging两个java配置文件。 ApplicationBootstrap.java
public class ApplicationBootstrap implements WebApplicationInitializer {
//public class Initializer
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationConfig.class);
rootContext.refresh();
// Manage the lifecycle of the root appcontext
servletContext.addListener(new ContextLoaderListener(rootContext));
servletContext.setInitParameter("defaultHtmlEscape", "true");
servletContext.setInitParameter("spring.profiles.active", "Production");
// now the config for the Dispatcher servlet
AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
mvcContext.register(ApplicationConfig.class);
mvcContext.getEnvironment().setActiveProfiles("Production");
mvcContext.getEnvironment().setDefaultProfiles("Production");
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/api/*");
}
和ApplicationConfig.java
@Configuration()
@Profile({"Production", "ControllerUnitTest"})
@EnableWebMvc
@ComponentScan(basePackages = "com.consius.activework.server" )
@EnableAspectJAutoProxy
public class ApplicationConfig extends WebMvcConfigurerAdapter {
}
此担任espected。没有我的问题开始。我的想法是使用spring-security,并且寻找一种使用Java配置spring-security的方法。 过了一段时间我放弃了,我发现没有办法使用Java配置spring-security。 我决定回到XML的安全配置。
我创建了一个包含这一个web.xml:
<filter>
<filter-name>filterChainProxy</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>filterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
到ApplicationConfig.java我说:
@ImportResource({ "classpath:/spring-security.xml" })
并创建一个新的XML文件命名为弹簧的security.xml
<security:http auto-config='true' create-session="never" realm="Restricted Service" use-expressions="true">
<security:intercept-url pattern="/rest/**" access="permitAll()" />
</security:http>
根据文档,这是最小的配置。
试图运行此提供了以下错误(我无法理解为什么)
SEVERE: Exception starting filter filterChainProxy
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'filterChainProxy' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:549)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1096)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:278)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1121)
at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326)
at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:236)
at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:194)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
谁能帮助我? 我想我已经做了一些明显的错误,但我无法看到它。
// LG
我改个名字,,但错误仍然存在:: - 严重:异常开始过滤springSecurityFilterChain org.springframework.beans.factory.NoSuchBeanDefinitionException:无豆命名为“springSecurityFilterChain”的定义 \t在org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:549) \t在org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1096) – 2013-02-16 15:26:00
@ lg.lindstrom刚添加类似问题的链接 – ben75 2013-02-16 15:49:15