为什么在进行spring-security jdbc身份验证时出现错误?

时间:2020-04-22 20:36:24

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

springframework版本5.0.2。发行

springsecurity-version 5.0.0.RELEASE

DemoAppConfig

!message

我认为我从@Configuration批注中得到了错误

每次我运行服务器时,它都会加载一段时间并最终给出异常

DemoSecurityConfig

@Configuration
@EnableWebMvc
@ComponentScan(basePackages="com.luv2code.springsecurity.demo")
@PropertySource("classpath:persistence-mysql.properties")
public class DemoAppConfig {

@Autowired
private Environment env;


@Bean
public ViewResolver viewResolver(){
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();

    viewResolver.setPrefix("/WEB-INF/view/");
    viewResolver.setSuffix(".jsp");

    return viewResolver;
}


@Bean
public DataSource securityDatasoruce(){

    ComboPooledDataSource securityDataSource
                            = new ComboPooledDataSource();


     try {

         securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));

     } catch (PropertyVetoException exc) {

         exc.printStackTrace();
     }


     securityDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
     securityDataSource.setUser(env.getProperty("jdbc.user"));
     securityDataSource.setPassword(env.getProperty("jdbc.password"));


     securityDataSource.setInitialPoolSize(
             getIntProperty("connection.pool.initialPoolSize"));
     securityDataSource.setMinPoolSize(
             getIntProperty("connection.pool.minPoolSize"));
     securityDataSource.setMaxPoolSize(
             getIntProperty("connection.pool.maxPoolSize"));
     securityDataSource.setMaxIdleTime(
             getIntProperty("connection.pool.maxIdleTime"));

    return securityDatasoruce();

}

private int getIntProperty(String propName){

        String propVal=env.getProperty(propName);

        int intPropVal=Integer.parseInt(propVal);

        return intPropVal;

    }
  }

在com.luv2code.springsecurity.demo.config.DemoAppConfig $$ EnhancerBySpringCGLIB $$ b4328af6.securityDatasoruce() 在com.luv2code.springsecurity.demo.config.DemoAppConfig.securityDatasoruce(DemoAppConfig.java:81) 在com.luv2code.springsecurity.demo.config.DemoAppConfig $$ EnhancerBySpringCGLIB $$ b4328af6.CGLIB $ securityDatasoruce $ 0() 在com.luv2code.springsecurity.demo.config.DemoAppConfig $$ EnhancerBySpringCGLIB $$ b4328af6 $$ FastClassBySpringCGLIB $$ 5fac1996.invoke() 在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 在org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)处 在com.luv2code.springsecurity.demo.config.DemoAppConfig $$ EnhancerBySpringCGLIB $$ b4328af6.securityDatasoruce() 在com.luv2code.springsecurity.demo.config.DemoAppConfig.securityDatasoruce(DemoAppConfig.java:81) 在com.luv2code.springsecurity.demo.config.DemoAppConfig $$ EnhancerBySpringCGLIB $$ b4328af6.CGLIB $ securityDatasoruce $ 0() 在com.luv2code.springsecurity.demo.config.DemoAppConfig $$ EnhancerBySpringCGLIB $$ b4328af6 $$ FastClassBySpringCGLIB $$ 5fac1996.invoke() 在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)

1 个答案:

答案 0 :(得分:0)

您已在DemoAppConfig中返回了函数而不是变量

更改返回securityDatasoruce();返回securityDataSource

现在应该可以正常工作

相关问题