Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring安全初始化在mvcContentNegotiationManager上引发未满足的PendencyException_Java_Spring_Spring Mvc_Spring Security - Fatal编程技术网

Java Spring安全初始化在mvcContentNegotiationManager上引发未满足的PendencyException

Java Spring安全初始化在mvcContentNegotiationManager上引发未满足的PendencyException,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我正在尝试在一个现有的Spring MVC项目中实现Spring Security 5.0.0版本。请注意,它完全基于注释 以下是myWebAppInitializer的代码: package com.abc.webapp.core; public class WebAppInitializer implements WebApplicationInitializer{ @Override public void onStartup(ServletContext contain

我正在尝试在一个现有的Spring MVC项目中实现Spring Security 5.0.0版本。请注意,它完全基于注释

以下是my
WebAppInitializer
的代码:

package com.abc.webapp.core;

public class WebAppInitializer implements WebApplicationInitializer{
    @Override
    public void onStartup(ServletContext container) throws ServletException {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.setConfigLocation("com.abc.webapp.config");
        container.addListener(new ContextLoaderListener(context));
        ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcherServlet",
                new DispatcherServlet(context));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }
}
以下是
WebMVCConfig
文件-

package com.abc.webapp.config;

@EnableWebMvc
@Configuration
@ComponentScan(basePackages = { "com.abc.webapp.controller" })
public class AppContextWebConfig extends WebMvcConfigurerAdapter {

    @Bean
    public InternalResourceViewResolver resolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setViewClass(JstlView.class);
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/css/**").addResourceLocations("/WEB-INF/css/");
        registry.addResourceHandler("/resources/js/**").addResourceLocations("/WEB-INF/js/");
    }
}
现在,根据我正在尝试的配置如下-

package com.abc.webapp.config;

@EnableWebSecurity
@Configuration
public class AppContextSecurityConfig extends WebSecurityConfigurerAdapter{

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().
                withUser(User.withDefaultPasswordEncoder()
                        .username("user")
                        .password("password")
                        .roles("USER")
                );
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
       // Code for Login URL and Logout URL 
    }
}

当我试图启动服务器时,我得到以下堆栈跟踪

[ERROR][2018-01-30 01:40:13 ContextLoader:351] - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appContextSecurityConfig': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0: Error creating bean with name 'mvcContentNegotiationManager' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.accept.ContentNegotiationManager]: Factory method 'mvcContentNegotiationManager' threw exception; nested exception is java.lang.AbstractMethodError; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.accept.ContentNegotiationManager]: Factory method 'mvcContentNegotiationManager' threw exception; nested exception is java.lang.AbstractMethodError
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:651)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
我很确定我没有错过Srping设置中提到的任何步骤。我在谷歌上搜索了好几次,但都没用。我还尝试删除
SecurityWebAppInitializer
,并按以下方式手动在
WebAppInitializer
中添加过滤器

FilterRegistration.Dynamic  springSecurityFilterChain = container.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*");

在启动过程中,我仍然会遇到异常。非常感谢您提供任何线索或解决方案。

这可能是由于您的spring-web-X.X.X.RELEASE.jar、spring Data Commons jar不兼容所致。请使用以下命令检查SpringJAR版本

mvn dependency:tree.

由于您的完整代码不可用,因此您似乎在代码中的某个位置自动连接了一个依赖项
mvcContentNegotiationManager
。有吗?我没有在配置类的任何地方显式地自动连接mvcContentNegotiationManager。你还能想到其他线索吗?你用的是弹簧靴吗?如果是的话,SpringBoot的版本是什么?我认为这是SpringWeb的jar版本问题。您是否尝试过使用eclipse分析pom.xml。使用eclipe打开pom.xml,进入依赖层次结构并搜索spiring web的版本。应该有一个版本。最好粘贴pom.xml和其他配置文件
mvn dependency:tree.