Merge pull request #4493 from eugenp/update-mvc-java
update to spring 5
This commit is contained in:
@@ -3,7 +3,7 @@ package com.baeldung.app;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.dialect;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.baeldung.processor.NameProcessor;
|
||||
import org.thymeleaf.dialect.AbstractDialect;
|
||||
import org.thymeleaf.processor.IProcessor;
|
||||
|
||||
public class CustomDialect extends AbstractDialect {
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return "custom";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IProcessor> getProcessors() {
|
||||
final Set<IProcessor> processors = new HashSet<IProcessor>();
|
||||
processors.add(new NameProcessor());
|
||||
return processors;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.processor;
|
||||
|
||||
import org.thymeleaf.Arguments;
|
||||
import org.thymeleaf.dom.Element;
|
||||
import org.thymeleaf.processor.attr.AbstractTextChildModifierAttrProcessor;
|
||||
|
||||
public class NameProcessor extends AbstractTextChildModifierAttrProcessor {
|
||||
|
||||
public NameProcessor() {
|
||||
super("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getText(final Arguments arguements, final Element elements, final String attributeName) {
|
||||
return "Hello, " + elements.getAttributeValue(attributeName) + "!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPrecedence() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.baeldung.spring.web.config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.baeldung.dialect.CustomDialect;
|
||||
import javax.servlet.ServletContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -13,27 +11,28 @@ import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.servlet.view.JstlView;
|
||||
import org.thymeleaf.dialect.IDialect;
|
||||
import org.thymeleaf.spring4.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
|
||||
|
||||
@EnableWebMvc
|
||||
@Configuration
|
||||
public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
||||
public class ClientWebConfig implements WebMvcConfigurer {
|
||||
|
||||
public ClientWebConfig() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
@Autowired
|
||||
private ServletContext ctx;
|
||||
|
||||
@Override
|
||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||
super.addViewControllers(registry);
|
||||
|
||||
registry.addViewController("/sample.html");
|
||||
}
|
||||
@@ -59,7 +58,7 @@ public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
||||
@Bean
|
||||
@Description("Thymeleaf template resolver serving HTML 5")
|
||||
public ServletContextTemplateResolver templateResolver() {
|
||||
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
|
||||
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx);
|
||||
templateResolver.setPrefix("/WEB-INF/templates/");
|
||||
templateResolver.setSuffix(".html");
|
||||
templateResolver.setTemplateMode("HTML5");
|
||||
@@ -71,9 +70,6 @@ public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
||||
public SpringTemplateEngine templateEngine() {
|
||||
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
|
||||
templateEngine.setTemplateResolver(templateResolver());
|
||||
final Set<IDialect> dialects = new HashSet<>();
|
||||
dialects.add(new CustomDialect());
|
||||
templateEngine.setAdditionalDialects(dialects);
|
||||
return templateEngine;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user