diff --git a/continew-starter-api-doc/src/main/java/top/charles7c/continew/starter/apidoc/autoconfigure/SpringDocAutoConfiguration.java b/continew-starter-api-doc/src/main/java/top/charles7c/continew/starter/apidoc/autoconfigure/SpringDocAutoConfiguration.java index 18f701fe..a9103d7a 100644 --- a/continew-starter-api-doc/src/main/java/top/charles7c/continew/starter/apidoc/autoconfigure/SpringDocAutoConfiguration.java +++ b/continew-starter-api-doc/src/main/java/top/charles7c/continew/starter/apidoc/autoconfigure/SpringDocAutoConfiguration.java @@ -27,9 +27,15 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.PropertySource; -import top.charles7c.continew.starter.core.autoconfigure.ProjectProperties; +import org.springframework.http.CacheControl; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties; import top.charles7c.continew.starter.core.handler.GeneralPropertySourceFactory; +import java.util.concurrent.TimeUnit; + /** * API 文档自动配置 @@ -38,10 +44,19 @@ import top.charles7c.continew.starter.core.handler.GeneralPropertySourceFactory; * @since 1.0.0 */ @Slf4j +@EnableWebMvc @AutoConfiguration @ConditionalOnProperty(name = "springdoc.swagger-ui.enabled", havingValue = "true") @PropertySource(value = "classpath:default-api-doc.yml", factory = GeneralPropertySourceFactory.class) -public class SpringDocAutoConfiguration { +public class SpringDocAutoConfiguration implements WebMvcConfigurer { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/"); + registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/") + .setCacheControl(CacheControl.maxAge(5, TimeUnit.HOURS).cachePublic()); + } /** * Open API 配置 diff --git a/continew-starter-api-doc/src/main/java/top/charles7c/continew/starter/apidoc/autoconfigure/StaticResourceAutoConfiguration.java b/continew-starter-api-doc/src/main/java/top/charles7c/continew/starter/apidoc/autoconfigure/StaticResourceAutoConfiguration.java deleted file mode 100644 index c5204222..00000000 --- a/continew-starter-api-doc/src/main/java/top/charles7c/continew/starter/apidoc/autoconfigure/StaticResourceAutoConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. - *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *
- * http://www.gnu.org/licenses/lgpl.html - *
- * 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 top.charles7c.continew.starter.apidoc.autoconfigure; - -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.http.CacheControl; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -import java.util.concurrent.TimeUnit; - -/** - * 静态资源处理器自动配置 - * - * @author Charles7c - * @since 1.0.0 - */ -@EnableWebMvc -@AutoConfiguration -@ConditionalOnProperty(name = "springdoc.swagger-ui.enabled", havingValue = "true") -public class StaticResourceAutoConfiguration implements WebMvcConfigurer { - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/"); - registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/") - .setCacheControl(CacheControl.maxAge(5, TimeUnit.HOURS).cachePublic()); - } -} diff --git a/continew-starter-api-doc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/continew-starter-api-doc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index e48225e8..4af5adbf 100644 --- a/continew-starter-api-doc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/continew-starter-api-doc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,2 +1 @@ -top.charles7c.continew.starter.apidoc.autoconfigure.SpringDocAutoConfiguration -top.charles7c.continew.starter.apidoc.autoconfigure.StaticResourceAutoConfiguration \ No newline at end of file +top.charles7c.continew.starter.apidoc.autoconfigure.SpringDocAutoConfiguration \ No newline at end of file