自定义弹簧条件导致java.lang.NoSuchMethodException:<init>()异常

人体模型84

我只是试图覆盖WebSecurityConfiguration的默认行为,并且不得不编写自己的条件以基于定义的属性来启动Bean。我的自定义条件类中没有定义arg构造函数。无论如何,java.lang.NoSuchMethodException启动应用程序时都会得到

这是我的代码的样子:

@Configuration
@ConditionalOnClass(WebSecurityConfigurerAdapter.class)
@Slf4j
public class WebSecurityConfiguration {

    class DefaultSecurityCondition implements Condition {

        public DefaultSecurityCondition(){}

        @Override
        public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

            if (context.getEnvironment().getProperty("property.server.authorised-clients") == null &&
                    context.getEnvironment().getProperty("property.server.authorised-thumbprints") == null) {
                return true;
            }
            return false;
        }
    }    


    @Configuration
    @Conditional(DefaultSecurityCondition.class)
    @EnableWebSecurity
    public class DefaultAuthorisationConfiguration extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().antMatchers("/").permitAll()
                    .and().httpBasic().disable().authorizeRequests()
                    .and().csrf().disable();
        }
    }
    }

但是,当我尝试启动我的应用程序时,出现以下异常。

java.lang.NoSuchMethodException:com.test.WebSecurityConfiguration $ DefaultSecurityCondition。()

我究竟做错了什么?

安迪·威尔金森

如果是内部类,则DefaultSecurityCondition必须声明static如果不是static,则必须创建实例,否则必须具有其外部类的实例。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

java.lang.NoSuchMethodException: <init> []

导致此异常的原因java.lang.RuntimeException:java.lang.NoSuchMethodException:<init> [class android.view.View]

Kotlin java.lang.NoSuchMethodException:<init>()

java.lang.NoSuchMethodException:AffirmativeBased。<init>()

java.lang.NoSuchMethodException: <Class>.<init>(java.lang.String) 复制自定义 Transformer 时

启动服务器时发生异常:java.lang.NoSuchMethodException:org.springframework.security.authentication.ProviderManager。<init>()

java.lang.NoSuchMethodException:userAuth.User。<init>()

java.lang.NoSuchMethodException:package.ClassName。<init>()使用Class <?>

Scala案例类中的init方法的java.lang.NoSuchMethodException

错误:java.lang.NoSuchMethodException:Spring MVC中的java.lang.Long。<init>()

Java反射:原始int的构造函数原因:java.lang.NoSuchMethodException:int。<init>(int)

启动Servlet筛选器时如何解决java.lang.NoSuchMethodException:package.MyCustomFilter。<init>()

引起:java.lang.NoSuchMethodException: <init> [class android.app.Application] - viewmodel

找不到默认的构造函数;嵌套异常是Spring MVC的java.lang.NoSuchMethodException?

线程“主”中的异常java.lang.NoSuchMethodException:添加ArrayList之后

Spring请求处理失败;嵌套异常是 java.lang.NoSuchMethodException:

引起原因:java.lang.NoSuchMethodException:<init> [class android.content.Context,接口android.util.AttributeSet]

创建名称为'application'的bean时出错,找不到默认的构造函数;嵌套的异常是java.lang.NoSuchMethodException

java.lang.NoSuchMethodException为的onCreate

java.lang.NoSuchMethodException struts servlet

android java.lang.AssertionError:java.lang.NoSuchMethodException-Proguard

java.lang.RuntimeException:java.lang.NoSuchMethodException:Hadoop mapreduce

未处理的异常:NoSuchMethodException

init 方法调用失败;嵌套异常是 java.lang.IllegalArgumentException: 'sessionFactory' 或 'hibernateTemplate' 是必需的

线程“主”中的异常java.lang.NoSuchMethodError:scala.Product。$ init $(Lscala / Product;)

春季安全性Java NoSuchMethodException:SecurityConfig。<init>()

Java反射错误Java.lang.NoSuchMethodException,但是方法存在

java.lang.NoSuchMethodException:Bean没有名为的属性

引起:java.lang.NoSuchMethodException Spring Batch xml配置