始终配置构建路径

时间:2018-07-04 08:24:42

标签: spring-boot

我正在尝试使用SpringBoot开发应用程序。

我尝试了10000种不同的方式,并且总是出现相同的错误“ configure build path”。

我有一个用于CORS的代码,但是我更改了这些代码,因为:“ configure build path”

我在pom.xml中添加了新的依赖项

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>5.0.3.RELEASE</version>
 </dependency>

很棒!!我没有错误“ configure ........”,然后当我以SpringBoot App运行时

我收到此错误:passwordencoder-mapped-for-the-id-null,我读了inf并更改了代码:

package com.service.configure;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Configuration
@EnableWebSecurity
@ComponentScan(basePackages = "com.service")

public class ServiciosConfig  extends WebSecurityConfigurerAdapter {

    //@Value("${usrRest}")
    private String usrRest; 

    //@Value("${passRest}")
    private String passRest; 
    //@PropertySource("file:${ruta_properties}")


    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers(HttpMethod.OPTIONS);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
           http
           .csrf()
               .disable()
           .authorizeRequests()
               .anyRequest().authenticated()
           .and()
               .httpBasic()
           .and()
               .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
           auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser("test1").password("test1").roles("ADMIN");
    }

     @Bean
        public  static PropertySourcesPlaceholderConfigurer propertyDefaultConfig() {
            return new PropertySourcesPlaceholderConfigurer();
        }   


}

.passwordEncoder(new BCryptPasswordEncoder())我又遇到了同样的错误->在eclipse中配置构建路径...

Error creating bean with name 'propertyDefaultConfig' defined in class path resource [com/service/configure/ServiciosConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.context.support.PropertySourcesPlaceholderConfigurer]: Factory method 'propertyDefaultConfig' threw exception; nested exception is java.lang.Error: Unresolved compilation problem: 

    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.18.RELEASE.jar:4.3.18.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1181) ~[spring-beans-4.3.18.RELEASE.jar:4.3.18.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1075) ~[spring-beans-4.3.18.RELEASE.jar:4.3.18.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.18.RELEASE.jar:4.3.18.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.18.RELEASE.jar:4.3.18.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.18.RELEASE.jar:4.3.18.RELEASE]

0 个答案:

没有答案