Reflect grouping in directory structure

This commit is contained in:
Andy Wilkinson
2022-10-28 14:36:50 +01:00
parent 393e1cb6bf
commit 7112a4b6a4
788 changed files with 9 additions and 100 deletions

View File

@@ -0,0 +1,24 @@
package com.example.conditional;
import com.example.conditional.ConditionalConfig.SomeBean;
import org.springframework.boot.CommandLineRunner;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
@Component
public class CLR implements CommandLineRunner {
private final SomeBean someBean;
public CLR(@Nullable SomeBean someBean) {
this.someBean = someBean;
}
@Override
public void run(String... args) throws Exception {
// someBean is only there if TrickyCondition matched
System.out.printf("TrickyCondition matched: %b", this.someBean != null);
}
}

View File

@@ -0,0 +1,14 @@
package com.example.conditional;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ConditionalApplication {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(ConditionalApplication.class, args);
Thread.currentThread().join(); // To be able to measure memory consumption
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2019-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.conditional;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
@Configuration
@Conditional(TrickyCondition.class)
class ConditionalConfig {
@Bean
SomeBean getBean() {
return new SomeBean();
}
static class SomeBean {
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2019-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.conditional;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
class TrickyCondition extends AnyNestedCondition {
private TrickyCondition() {
super(ConfigurationPhase.REGISTER_BEAN);
}
@ConditionalOnClass(String.class)
static class Inner {
Inner() {
}
}
}