IdentifierGeneratorAutoConfiguration.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2011-2022, baomidou (jobob@qq.com).
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.baomidou.mybatisplus.autoconfigure;
  17. import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
  18. import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
  19. import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
  20. import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
  21. import org.springframework.cloud.commons.util.InetUtils;
  22. import org.springframework.context.annotation.Bean;
  23. import org.springframework.context.annotation.Configuration;
  24. import org.springframework.context.annotation.Lazy;
  25. /**
  26. * @author nieqiurong 2021/1/29
  27. * @since 3.4.3
  28. */
  29. @Lazy
  30. @Configuration(proxyBeanMethods = false)
  31. public class IdentifierGeneratorAutoConfiguration {
  32. @Configuration(proxyBeanMethods = false)
  33. @ConditionalOnClass(InetUtils.class)
  34. public static class InetUtilsAutoConfig {
  35. @Bean
  36. @ConditionalOnMissingBean
  37. public IdentifierGenerator identifierGenerator(InetUtils inetUtils) {
  38. return new DefaultIdentifierGenerator(inetUtils.findFirstNonLoopbackAddress());
  39. }
  40. }
  41. }