public class GroovyMarkupConfigurer extends groovy.text.markup.TemplateConfiguration implements GroovyMarkupConfig, ApplicationContextAware, InitializingBean
TemplateConfiguration
の拡張と、Web アプリケーションで使用するための MarkupTemplateEngine
を作成するための Spring MVC の GroovyMarkupConfig
の実装。このクラスを構成する最も基本的な方法は、"resourceLoaderPath" を設定することです。例:// Add the following to an @Configuration class @Bean public GroovyMarkupConfig groovyMarkupConfigurer() { GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer(); configurer.setResourceLoaderPath("classpath:/WEB-INF/groovymarkup/"); return configurer; }デフォルトでは、この Bean は以下を使用して
MarkupTemplateEngine
を作成します。TemplateConfiguration
のデフォルト構成TemplateResolver
MarkupTemplateEngine
インスタンスをこの Bean に直接提供できます。その場合、他のすべてのプロパティは効果的に無視されません。 この Bean は、レンダリングに Spring MVC GroovyMarkupView
を使用するすべてのアプリケーションのアプリケーションコンテキストに含める必要があります。これは、Groovy のマークアップテンプレートを構成するためだけに存在します。アプリケーションコンポーネントから直接参照されることを意図したものではありません。Bean の名前に依存せずに GroovyMarkupView が見つけられる GroovyMarkupConfig を実装します。各 DispatcherServlet は、必要に応じて独自の GroovyMarkupConfigurer を定義できます。
MarkupTemplateEngine
では、リソースキャッシュがデフォルトで有効になっていることに注意してください。必要に応じて、TemplateConfiguration.setCacheTemplates(boolean)
を使用して構成します。
Spring の Groovy マークアップテンプレートのサポートには、Groovy 2.3.1 以上が必要です。
GroovyMarkupView
, Groovy マークアップテンプレートエンジンのドキュメントコンストラクターと説明 |
---|
GroovyMarkupConfigurer() |
修飾子と型 | メソッドと説明 |
---|---|
void | afterPropertiesSet() |
protected ClassLoaderSE | createTemplateClassLoader() テンプレートをロードおよびコンパイルするときに親 ClassLoader として使用する Groovy の親 ClassLoader を作成します。 |
protected groovy.text.markup.MarkupTemplateEngine | createTemplateEngine() |
protected ApplicationContext | getApplicationContext() |
StringSE | getResourceLoaderPath() |
groovy.text.markup.MarkupTemplateEngine | getTemplateEngine() 現在の Web アプリケーションコンテキストの Groovy MarkupTemplateEngine を返します。 |
protected URLSE | resolveTemplate(ClassLoaderSE classLoader, StringSE templatePath) 指定されたテンプレートパスからテンプレートを解決します。 |
void | setApplicationContext(ApplicationContext applicationContext) このオブジェクトが実行される ApplicationContext を設定します。 |
void | setLocale(LocaleSE locale) テンプレートを解決するために考慮されるロケールは現在の HTTP リクエストのロケールであるため、このメソッドは使用しないでください。 |
void | setResourceLoaderPath(StringSE resourceLoaderPath) Spring リソースの場所を介して Groovy マークアップテンプレートのリソースローダーパスを設定します。 |
void | setTemplateEngine(groovy.text.markup.MarkupTemplateEngine templateEngine) Groovy マークアップテンプレート Web 構成に使用するように事前構成済みの MarkupTemplateEngine を設定します。 |
getAutoIndentString, getBaseTemplateClass, getDeclarationEncoding, getLocale, getNewLineString, isAutoEscape, isAutoIndent, isAutoNewLine, isCacheTemplates, isExpandEmptyElements, isUseDoubleQuotes, setAutoEscape, setAutoIndent, setAutoIndentString, setAutoNewLine, setBaseTemplateClass, setCacheTemplates, setDeclarationEncoding, setExpandEmptyElements, setNewLineString, setUseDoubleQuotes
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public void setResourceLoaderPath(StringSE resourceLoaderPath)
ResourceLoader
で理解されているように、"file:" や "classpath:" などの標準 URL と疑似 URL がサポートされています。ApplicationContext で実行する場合、相対パスを使用できます。public StringSE getResourceLoaderPath()
public void setTemplateEngine(groovy.text.markup.MarkupTemplateEngine templateEngine)
この設定の他のすべての Bean プロパティは無視されるため、このエンジンインスタンスは手動で設定する必要があることに注意してください。
public groovy.text.markup.MarkupTemplateEngine getTemplateEngine()
GroovyMarkupConfig
MarkupTemplateEngine
を返します。1 つのサーブレットに固有の場合もあれば、ルートコンテキストで共有される場合もあります。GroovyMarkupConfig
の getTemplateEngine
public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAware
通常の Bean プロパティの設定後、ただし InitializingBean.afterPropertiesSet()
またはカスタム init メソッドなどの init コールバックの前に呼び出されます。ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
、ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
および MessageSourceAware
の後に呼び出されます(該当する場合)。
ApplicationContextAware
の setApplicationContext
applicationContext
- このオブジェクトによって使用される ApplicationContext オブジェクト BeanInitializationException
protected ApplicationContext getApplicationContext()
public void setLocale(LocaleSE locale)
groovy.text.markup.TemplateConfiguration
の setLocale
public void afterPropertiesSet() throws ExceptionSE
InitializingBean
BeanFactoryAware
、ApplicationContextAware
などを満たした後、包含 BeanFactory
によって呼び出されます。このメソッドにより、Bean インスタンスは、すべての Bean プロパティが設定されたときに、その全体的な構成の検証と最終的な初期化を実行できます。
InitializingBean
の afterPropertiesSet
ExceptionSE
- 構成の誤り(必須プロパティの設定の失敗など)の場合、またはその他の理由で初期化が失敗した場合 protected groovy.text.markup.MarkupTemplateEngine createTemplateEngine() throws IOExceptionSE
protected ClassLoaderSE createTemplateClassLoader() throws IOExceptionSE
protected URLSE resolveTemplate(ClassLoaderSE classLoader, StringSE templatePath) throws IOExceptionSE
デフォルトの実装では、LocaleContextHolder
で取得した現在のリクエストに関連付けられているロケールを使用して、テンプレートファイルを検索します。実際には、エンジンレベルで設定されたロケールは無視されます。