出於某種原因(我真的不能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