Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 Security Web应用程序上下文不';不要装豆子 问题_Java_Spring_Spring Security - Fatal编程技术网

Java Spring Security Web应用程序上下文不';不要装豆子 问题

Java Spring Security Web应用程序上下文不';不要装豆子 问题,java,spring,spring-security,Java,Spring,Spring Security,除了编程配置之外,我无法从springbeans.xml加载bean。我创建了一个自定义的org.springframework.security.config.annotation.web.configuration.websecurityConfigureAdapter,并用以下注释对该类进行了注释:@configuration、@ImportResource('classpath*:spring beans.xml')、@EnableWebSecurity。正如您在日志中看到的,没有加载b

除了编程配置之外,我无法从
springbeans.xml
加载bean。我创建了一个自定义的
org.springframework.security.config.annotation.web.configuration.websecurityConfigureAdapter
,并用以下注释对该类进行了注释:
@configuration、@ImportResource('classpath*:spring beans.xml')、@EnableWebSecurity
。正如您在日志中看到的,没有加载bean。为什么?我的目标是拥有半灵活的配置。我想在代码中配置一些部分,在spring-beans.xml文件中配置一些部分,这些部分应该在启动时加载到应用程序上下文中。例如,我想定义一个自定义AuthentificationProvider,并在spring-beans.xml文件中使用自定义配置创建它。应该在代码中修复对提供程序所做的操作

日志 Java代码 spring-beans.xml Java代码的编辑
更新代码后,日志保持不变:“加载了0个bean…”。

提供应用程序的文件夹结构将有助于正确回答此问题

同时,您可以尝试下面的解决方案-


假设该文件不在任何jar中,在
@ImportResource({“classpath*:springbeans.xml”})
中,指定bean定义文件的绝对路径。例如:
@ImportResource({“classpath:/configurations/springbeans.xml”})
提供应用程序的文件夹结构将有助于正确回答这个问题

同时,您可以尝试下面的解决方案-

假设该文件不在任何jar中,在
@ImportResource({“classpath*:springbeans.xml”})
中,指定bean定义文件的绝对路径。例如:
@ImportResource({“classpath:/configurations/springbeans.xml})
多亏了

为了解决这个问题,我只需要移动目录

修复前的结构

└── src
    └── main
        ├── java
        └── resources
            ├── META-INF
            └── spring
解决方案

└── src
    └── main
        ├── java
        ├── resources
        │   └── META-INF
        └── spring
感谢

为了解决这个问题,我只需要移动目录

修复前的结构

└── src
    └── main
        ├── java
        └── resources
            ├── META-INF
            └── spring
解决方案

└── src
    └── main
        ├── java
        ├── resources
        │   └── META-INF
        └── spring

谢谢你的回答。我试过你的建议,但不幸的是他们没有解决这个问题。请参阅我文章中关于项目结构的更新。让我试试这个项目结构,然后再回来。您的类路径应该是“/spring/spring beans.xml”-resources文件夹是一个Maven组织特性,当代码放在目标文件夹中时不会保留它。谢谢!这解决了这个问题。@oops您不需要更改文件夹结构。将您的
spring
文件夹保存在resources目录下。仅从导入资源中删除/删除资源。例如:
@ImportResource({“classpath:/spring/springbeans.xml})
谢谢你的回答。我试过你的建议,但不幸的是他们没有解决这个问题。请参阅我文章中关于项目结构的更新。让我试试这个项目结构,然后再回来。您的类路径应该是“/spring/spring beans.xml”-resources文件夹是一个Maven组织特性,当代码放在目标文件夹中时不会保留它。谢谢!这解决了这个问题。@oops您不需要更改文件夹结构。将您的
spring
文件夹保存在resources目录下。仅从导入资源中删除/删除资源。例如:
@ImportResource({“classpath:/spring/springbeans.xml})
├── src
│   ├── main
│   │   ├── java
│   │   ├── resources
│   │   │   ├── META-INF
│   │   │   └── spring
│   │   └── webapp
│   │       └── WEB-INF
│   └── test
│       └── java
@Configuration
@ImportResource({"classpath*:/resources/spring/spring-beans.xml"})
@EnableWebSecurity
public class HSecurityConfig extends WebSecurityConfigurerAdapter {

    // configuration creates a servlet filter known as 'springSecurityFilterChain'

    @Autowired ApplicationContext applicationContext;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // configure some http stuff
    }

}
└── src
    └── main
        ├── java
        └── resources
            ├── META-INF
            └── spring
└── src
    └── main
        ├── java
        ├── resources
        │   └── META-INF
        └── spring