pom
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.liuqd.springboot</groupId> <artifactId>springboot</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.boot.version>1.5.6.RELEASE</spring.boot.version> <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.2.1</thymeleaf-layout-dialect.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>4.3.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>${spring.boot.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <version>${spring.boot.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>${spring.boot.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf --> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf</artifactId> <version>${thymeleaf.version}</version> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 --> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring4</artifactId> <version>${thymeleaf.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.0.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.2</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build> </project>
/** * Created by who on 16-7-16. */@Configuration@Import(WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter.class)public class WebMvcConfig { @Configuration @EnableWebMvc @EnableConfigurationProperties({ThymeleafProperties.class}) public static class ThymeleafAutoConfiguration extends WebMvcConfigurerAdapter { @Autowired private ApplicationContext applicationContext; @Autowired private ThymeleafProperties thymeleafProperties; /** @Override public void addViewControllers(ViewControllerRegistry registry) { //registry.addViewController("/home").setViewName("home"); // registry.addViewController("/").setViewName("hello"); //registry.addViewController("/hello").setViewName("hello"); //registry.addViewController("/login").setViewName("login"); }*/ @Bean public ITemplateResolver templateResolver() { SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); templateResolver.setApplicationContext(applicationContext); templateResolver.setPrefix(thymeleafProperties.getPrefix()); templateResolver.setSuffix(thymeleafProperties.getSuffix()); templateResolver.setTemplateMode(TemplateMode.HTML); templateResolver.setCacheable(thymeleafProperties.isCache()); if (thymeleafProperties.getEncoding() != null) { templateResolver.setCharacterEncoding(thymeleafProperties.getEncoding().name()); } if (thymeleafProperties.getTemplateResolverOrder() != null) { templateResolver.setOrder(thymeleafProperties.getTemplateResolverOrder()); } return templateResolver; } @Bean public TemplateEngine templateEngine(ITemplateResolver templateResolver) { SpringTemplateEngine engine = new SpringTemplateEngine(); engine.setEnableSpringELCompiler(true); engine.setTemplateResolver(templateResolver); return engine; } @Bean public ViewResolver viewResolver(ITemplateEngine templateEngine) { ThymeleafViewResolver resolver = new ThymeleafViewResolver(); resolver.setTemplateEngine(templateEngine); resolver.setCharacterEncoding(thymeleafProperties.getEncoding().name()); resolver.setContentType(appendCharset(this.thymeleafProperties.getContentType(), resolver.getCharacterEncoding())); resolver.setExcludedViewNames(this.thymeleafProperties.getExcludedViewNames()); resolver.setViewNames(this.thymeleafProperties.getViewNames()); resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5); resolver.setCache(thymeleafProperties.isCache()); return resolver; }/****/ private String appendCharset(MimeType type, String charset) { if (type.getCharset() != null) { return type.toString(); } LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>(); parameters.put("charset", charset); parameters.putAll(type.getParameters()); return new MimeType(type, parameters).toString(); } } // ****************** druid monitor // access url /druid/index.html /** @Bean public ServletRegistrationBean druidServlet() { return new ServletRegistrationBean(new StatViewServlet(), "/druid/*"); } @Bean public FilterRegistrationBean filterRegistrationBean() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new WebStatFilter()); filterRegistrationBean.addUrlPatterns("/*"); filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); return filterRegistrationBean; }**/}
@SpringBootApplication(scanBasePackages = {"com"}, exclude = {org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration.class})
时间: 2024-08-08 00:17:39