Spring安全示例 - 无应用程序上下文

时间:2016-05-29 14:08:24

标签: java spring maven spring-mvc spring-security

我是Spring的新手并检查了Spring Security。在Spring网站上有HelloWorld Spring项目的链接。该项目可以由Maven导入并在Eclipse dev环境中运行。这个项目的有趣之处在于没有定义弹簧配置的web.xml或context.xml。

该项目包含两个类和一个index.jsp文件。

<select class = "form-control" id="changeDevice" name="changeDevice" >
   <option value= "  -- select a device -- " disabled selected value> -- select a device -- </option> 
        <?php
          foreach($device as $devicedrop){
          ?>
            <option value="<?php echo $devicedrop['id'] ?>">
    <?php echo $devicedrop['name'] ?> </option>
            <?php
            }
            ?>
</select>  
    <input type = "text" id="text"></input>
<script>
    $('#changeDevice').find('option:selected').text();
    var text = $(this);
    $('#text').prop(text);
</script>

这是配置类,另一个是初始化类。

@EnableWebSecurity
public class SecurityConfig {
// @formatter:off
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws      Exception {`enter code here`
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }
    // @formatter:on
}

我评论了 @EnableWebSecurity 并删除了注释并假设Spring Security将被禁用,但是没有。当我执行它时,它正在寻找未在任何地方实现的过滤器链。

怎么会发生这样的事情。我甚至尝试清理服务器工作目录,但仍然是相同的。

关于这个简单项目如何进行的任何想法?

1 个答案:

答案 0 :(得分:0)

如果您使用的是Spring Boot,那么如果spring-boot-starter-security位于类路径上,它会自动配置Web安全性。 请参考:

https://spring.io/guides/gs/securing-web/#initial

Spring web security: is @EnableWebSecurity obsolete?