-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core): allow missing WebMvcConfigurer class in classpath
- Loading branch information
Showing
4 changed files
with
59 additions
and
43 deletions.
There are no files selected for viewing
40 changes: 6 additions & 34 deletions
40
.../main/java/io/github/springwolf/core/configuration/SpringwolfUiResourceConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,12 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.configuration; | ||
|
||
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.autoconfigure.web.WebProperties; | ||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
// Highest so that all others will replace this configuration | ||
@Order(value = Ordered.HIGHEST_PRECEDENCE) | ||
public class SpringwolfUiResourceConfiguration implements WebMvcConfigurer { | ||
|
||
private final SpringwolfConfigProperties springwolfConfigProperties; | ||
private final WebProperties webProperties; | ||
private final WebMvcProperties webMvcProperties; | ||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
registry.addResourceHandler(springwolfConfigProperties.getPath().getBase() + "/**", webMvcProperties.getStaticPathPattern()) | ||
.addResourceLocations(buildStaticLocation()); | ||
} | ||
|
||
private String[] buildStaticLocation() { | ||
List<String> staticLocations = new ArrayList<>(Arrays.asList(webProperties.getResources().getStaticLocations())); | ||
staticLocations.add("classpath:/META-INF/resources/springwolf/"); | ||
|
||
return staticLocations.toArray(new String[0]); | ||
} | ||
|
||
} | ||
@ConditionalOnClass(WebMvcConfigurer.class) | ||
@Import(SpringwolfUiResourceConfigurer.class) | ||
public class SpringwolfUiResourceConfiguration {} |
41 changes: 41 additions & 0 deletions
41
...src/main/java/io/github/springwolf/core/configuration/SpringwolfUiResourceConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.configuration; | ||
|
||
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.autoconfigure.web.WebProperties; | ||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
@Order(value = Ordered.HIGHEST_PRECEDENCE) // Highest so that all others will replace this configuration | ||
public class SpringwolfUiResourceConfigurer implements WebMvcConfigurer { | ||
|
||
private final SpringwolfConfigProperties springwolfConfigProperties; | ||
private final WebProperties webProperties; | ||
private final WebMvcProperties webMvcProperties; | ||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
registry.addResourceHandler( | ||
springwolfConfigProperties.getPath().getBase() + "/**", webMvcProperties.getStaticPathPattern()) | ||
.addResourceLocations(buildStaticLocation()); | ||
} | ||
|
||
private String[] buildStaticLocation() { | ||
List<String> staticLocations = | ||
new ArrayList<>(Arrays.asList(webProperties.getResources().getStaticLocations())); | ||
staticLocations.add("classpath:/META-INF/resources/springwolf/"); | ||
|
||
return staticLocations.toArray(new String[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters