package tju.SpringBootSecurityJdbc.controller;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
public class MyCondition implements Condition{
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
Environment env=context.getEnvironment();
if(env.containsProperty("myswitch"))
{
String str=env.getProperty("myswitch");
if(str.equals("true"))return true;
}
return false;
}
}
package tju.SpringBootSecurityJdbc.controller;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Conditional(MyCondition.class)
public class AppController3 {
@RequestMapping("/halu2")
public String testme()
{
return "this is rest2!";
}
}
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot
spring.datasource.username=root
spring.datasource.password=root
logging.level.org.springframework.security=trace
spring.thymeleaf.cache=false
test.fgh.enabled=true
my.user.num=2
com.abc=fgh
myswitch=true