001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot; 018 019/** 020 * Class that exposes the Spring Boot version. Fetches the "Implementation-Version" 021 * manifest attribute from the jar file. 022 * <p> 023 * Note that some ClassLoaders do not expose the package metadata, hence this class might 024 * not be able to determine the Spring Boot version in all environments. Consider using a 025 * reflection-based check instead: For example, checking for the presence of a specific 026 * Spring Boot method that you intend to call. 027 * 028 * @author Drummond Dawson 029 * @since 1.3.0 030 */ 031public final class SpringBootVersion { 032 033 private SpringBootVersion() { 034 } 035 036 /** 037 * Return the full version string of the present Spring Boot codebase, or {@code null} 038 * if it cannot be determined. 039 * @return the version of Spring Boot or {@code null} 040 * @see Package#getImplementationVersion() 041 */ 042 public static String getVersion() { 043 Package pkg = SpringBootVersion.class.getPackage(); 044 return (pkg != null) ? pkg.getImplementationVersion() : null; 045 } 046 047}