daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jul 22nd, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. apply plugin: 'java'
  2. apply plugin: 'war'
  3.  
  4. group = 'io.example'
  5. version = '0.0.1-SNAPSHOT'
  6. sourceCompatibility = 1.8
  7.  
  8. repositories {
  9.     mavenCentral()
  10. }
  11.  
  12. dependencies {
  13.     compileOnly('org.projectlombok:lombok:1.18.0')
  14.     compileOnly('javax.servlet:javax.servlet-api:4.0.1')
  15.     compile('org.apache.logging.log4j:log4j-core:2.11.0')
  16.     compile('javax.mail:javax.mail-api:1.6.1')
  17.     compile('org.springframework:spring-webmvc:5.0.7.RELEASE')
  18.     compile('org.thymeleaf:thymeleaf:3.0.9.RELEASE')
  19.     compile('org.thymeleaf:thymeleaf-spring5:3.0.9.RELEASE')
  20.     compile('org.springframework.data:spring-data-jpa:2.0.8.RELEASE')
  21.     compile('org.hibernate:hibernate-core:5.3.2.Final')
  22.     compile('com.zaxxer:HikariCP:3.2.0')
  23.     testCompile('org.springframework:spring-test:5.0.7.RELEASE')
  24.     testCompile('org.junit.platform:junit-platform-launcher:1.2.0')
  25.     testCompile('org.junit.jupiter:junit-jupiter-engine:5.2.0')
  26.     testCompile('org.mockito:mockito-junit-jupiter:2.19.1')
  27. }
  28.  
  29. configurations {
  30.     runtime.exclude group: 'org.slf4j'
  31.     compile.exclude group: 'org.slf4j'
  32. }
  33.    
  34. package io.example.spring.config;
  35.  
  36. import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
  37.  
  38. public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  39.     @Override
  40.     protected Class<?>[] getRootConfigClasses() {
  41.         return new Class[] { RootContextConfig.class };
  42.     }
  43.  
  44.     @Override
  45.     protected Class<?>[] getServletConfigClasses() {
  46.         return new Class[] { WebMvcConfig.class };
  47.     }
  48.  
  49.     @Override
  50.     protected String[] getServletMappings() {
  51.         return new String[] { "/" };
  52.     }
  53. }
  54.    
  55. package io.example.spring.config;
  56.  
  57. import lombok.extern.log4j.Log4j2;
  58. import org.springframework.beans.BeansException;
  59. import org.springframework.context.ApplicationContext;
  60. import org.springframework.context.ApplicationContextAware;
  61. import org.springframework.context.annotation.Bean;
  62. import org.springframework.context.annotation.ComponentScan;
  63. import org.springframework.context.annotation.Configuration;
  64. import org.springframework.context.support.ResourceBundleMessageSource;
  65. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  66. import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  67. import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
  68. import org.thymeleaf.spring5.SpringTemplateEngine;
  69. import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
  70. import org.thymeleaf.spring5.view.ThymeleafViewResolver;
  71. import org.thymeleaf.templatemode.TemplateMode;
  72.  
  73. @Configuration
  74. @EnableWebMvc
  75. @ComponentScan(basePackages = { "io.example" })
  76. @Log4j2
  77. public class WebMvcConfig extends WebMvcConfigurationSupport implements ApplicationContextAware {
  78.  
  79.     private ApplicationContext applicationContext;
  80.  
  81.     public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
  82.         this.applicationContext = applicationContext;
  83.     }
  84.  
  85.     @Override
  86.     public void addResourceHandlers(final ResourceHandlerRegistry registry) {
  87.         super.addResourceHandlers(registry);
  88.         registry.addResourceHandler("/res/**").addResourceLocations("/resources/");
  89.         log.info("Does the registry have mapping {}", registry.hasMappingForPattern("/res/**"));
  90.     }
  91.  
  92.     @Bean
  93.     public ResourceBundleMessageSource messageSource() {
  94.         ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
  95.         messageSource.setBasename("Messages");
  96.         return messageSource;
  97.     }
  98.  
  99.     @Bean
  100.     public SpringResourceTemplateResolver templateResolver(){
  101.         SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
  102.         templateResolver.setApplicationContext(this.applicationContext);
  103.         templateResolver.setPrefix("/WEB-INF/templates/");
  104.         templateResolver.setSuffix(".html");
  105.         templateResolver.setTemplateMode(TemplateMode.HTML);
  106.         templateResolver.setCacheable(true);
  107.         return templateResolver;
  108.     }
  109.  
  110.     @Bean
  111.     public SpringTemplateEngine templateEngine(){
  112.         SpringTemplateEngine templateEngine = new SpringTemplateEngine();
  113.         templateEngine.setTemplateResolver(templateResolver());
  114.         templateEngine.setEnableSpringELCompiler(true);
  115.         return templateEngine;
  116.     }
  117.  
  118.     @Bean
  119.     public ThymeleafViewResolver viewResolver(){
  120.         ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
  121.         viewResolver.setTemplateEngine(templateEngine());
  122.         viewResolver.setCharacterEncoding("UTF-8");
  123.         return viewResolver;
  124.     }
  125. }
  126.    
  127. package io.example.controller;
  128.  
  129. import lombok.extern.log4j.Log4j2;
  130. import org.springframework.stereotype.Controller;
  131. import org.springframework.ui.Model;
  132. import org.springframework.web.bind.annotation.RequestMapping;
  133.  
  134. @Controller
  135. @RequestMapping(path = "/ba")
  136. @Log4j2
  137. public class HelloController {
  138.  
  139.     @RequestMapping(path = "/hello")
  140.     public String sayHello(Model model) {
  141.         log.info("HelloController.sayHello() called . . . ");
  142.         model.addAttribute("name", "John");
  143.         return "hello";
  144.     }
  145.  
  146.     @RequestMapping(path = "/login")
  147.     public String loginLoad(Model model) {
  148.         log.info("HelloController.loginLoad() called . . . ");
  149.         return "login";
  150.     }
  151. }
  152.    
  153. 21:17:29.704 [http-nio-8080-exec-3] TRACE org.springframework.web.servlet.DispatcherServlet - Bound request context to thread: org.apache.catalina.connector.RequestFacade@3618aa7d
  154. 21:17:29.704 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/res/css/bulma.min.css]
  155. 21:17:29.704 [http-nio-8080-exec-3] TRACE org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@1c8d9b17] in DispatcherServlet with name 'dispatcher'
  156. 21:17:29.704 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /res/css/bulma.min.css
  157. 21:17:29.706 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/res/css/bulma.min.css]
  158. 21:17:29.706 [http-nio-8080-exec-3] TRACE org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@473d0890] in DispatcherServlet with name 'dispatcher'
  159. 21:17:29.706 [http-nio-8080-exec-3] TRACE org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping - No handler mapping found for [/res/css/bulma.min.css]
  160. 21:17:29.706 [http-nio-8080-exec-3] TRACE org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@35f4e4ad] in DispatcherServlet with name 'dispatcher'
  161. 21:17:29.706 [http-nio-8080-exec-3] TRACE org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@2c70dd07] in DispatcherServlet with name 'dispatcher'
  162. 21:17:29.706 [http-nio-8080-exec-3] TRACE org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@ba3770a] in DispatcherServlet with name 'dispatcher'
  163. 21:17:29.706 [http-nio-8080-exec-3] WARN  org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/res/css/bulma.min.css] in DispatcherServlet with name 'dispatcher'
  164. 21:17:29.706 [http-nio-8080-exec-3] TRACE org.springframework.web.servlet.DispatcherServlet - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@3618aa7d
  165. 21:17:29.706 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
  166. 21:17:29.706 [http-nio-8080-exec-3] TRACE org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Publishing event in WebApplicationContext for namespace 'dispatcher-servlet': ServletRequestHandledEvent: url=[/res/css/bulma.min.css]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[dispatcher]; session=[null]; user=[null]; time=[2ms]; status=[OK]
  167. 21:17:29.706 [http-nio-8080-exec-3] TRACE org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/res/css/bulma.min.css]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[dispatcher]; session=[null]; user=[null]; time=[2ms]; status=[OK]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top