最終的に、カスタム UriLocator に依存するのではなく、Spring 管理の ThemeManagerService をカスタム ポスト プロセッサに直接提供することができました。私は早い段階でそれを試みましたが、新しいコンストラクターで super() を呼び出すのを忘れていたため、プロセッサ登録システムが壊れていました。
WRO Bean を登録するときに 、@Autowired
ThemeManagerService
を myに渡します。CustomConfigurableWroManagerFactory
@Autowired
ThemeManagerService themeManagerService;
@Bean
FilterRegistrationBean webResourceOptimizer(Environment env) {
FilterRegistrationBean fr = new FilterRegistrationBean();
ConfigurableWroFilter filter = new ConfigurableWroFilter();
Properties props = buildWroProperties(env);
filter.setProperties(props);
//The overridden constructor passes ThemeManager along
filter.setWroManagerFactory(new CustomConfigurableWroManagerFactory(props,themeManagerService));
filter.setProperties(props);
fr.setFilter(filter);
fr.addUrlPatterns("/wro/*");
return fr;
}
へのコンストラクター注入は、次のように登録されているカスタム ポストプロセッサーに渡すことができることを意味しThemeManagerService
ます。CustomConfigurableWroManagerFactory
contributePostProcessors
public class CustomConfigurableWroManagerFactory extends Wro4jCustomXmlModelManagerFactory {
private ThemeManagerService themeManagerService;
public CustomConfigurableWroManagerFactory(Properties props,ThemeManagerService themeManagerService) {
//forgetting to call super derailed me early on
super(props);
this.themeManagerService = themeManagerService;
}
@Override
protected void contributePostProcessors(Map<String, ResourcePostProcessor> map) {
//ThemeManagerService is provided as the custom processor is registered
map.put("repoPostProcessor", new RepoPostProcessor(themeManagerService));
}
}
これで、ポスト プロセッサはThemeManagerService
以下にアクセスできるようになりました。
@SupportedResourceType(ResourceType.CSS)
public class RepoPostProcessor implements ResourcePostProcessor {
private ThemeManagerService themeManagerService;
public RepoPostProcessor(ThemeManagerService themeManagerService) {
super();
this.themeManagerService = themeManagerService;
}
public void process(final Reader reader, final Writer writer) throws IOException {
String resourceText = "/* The custom PostProcessor fetched the following SASS vars from the ThemeManagerService: */\n\n";
resourceText += themeManagerService.getFormattedProperties();
writer.append(resourceText);
//read in the merged SCSS and add it after the custom content
writer.append(IOUtils.toString(reader));
reader.close();
writer.close();
}
}
このアプローチは、これまでのところ期待/意図どおりに機能しています。他の誰かにとって便利になることを願っています。
Wro4j は優れたツールであり、高く評価されています。