diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..8316cff --- /dev/null +++ b/README.MD @@ -0,0 +1,22 @@ +# Skeleton: SpringMVC (standalone) + +В данной ветке располагается пример *(заготовка, шаблон)* +для создания _WebApplication_ средствами **Spring Framework** +с использованием **Spring WebMVC** со встроенным сервером **Jetty**. + +## Сборка + +``` +mvn package +``` + +## Запуск + +``` +java -jar spring-mvc-1.0.1-SNAPSHOT.jar +``` + +По-умолчанию используются ip:port `127.0.0.1:8080`. Для изменения требуется добавить следующие параметры: + +- `-Dhost=0.0.0.0` - для указания IP адреса `0.0.0.0` +- `-Dport=80` - для указания порта `80` diff --git a/pom.xml b/pom.xml index 74145ca..5ade51c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,14 +7,17 @@ ru.dmitriymx.skeleton spring-mvc - 1.0-SNAPSHOT + 1.0.1-SNAPSHOT UTF-8 1.8 - 1.7.21 - 4.2.5.RELEASE - 9.4.0.v20161208 + 1.7.25 + 2.11.1 + 5.1.0.RELEASE + 9.4.12.v20180830 + lib + ru.dmitriymx.skeleton.springmvc.WebApp @@ -30,9 +33,14 @@ ${slf4j.version} - org.slf4j - slf4j-simple - ${slf4j.version} + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} @@ -69,7 +77,7 @@ org.projectlombok lombok - 1.16.16 + 1.18.2 org.thymeleaf @@ -85,7 +93,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.5.1 + 3.8.0 ${java.version} ${java.version} @@ -95,11 +103,43 @@ org.apache.maven.plugins maven-surefire-plugin - 2.15 + 2.22.0 -Dfile.encoding=${project.build.sourceEncoding} + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + true + ${dependencies.dir}/ + ${main.class} + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.1 + + ${project.build.directory}/${dependencies.dir}/ + provided + + + + copy-dependencies + package + + copy-dependencies + + + + diff --git a/src/main/java/ru/dmitriymx/skeleton/springmvc/SpringConfigMVC.java b/src/main/java/ru/dmitriymx/skeleton/springmvc/SpringConfigMVC.java index 1364d0c..b79c900 100644 --- a/src/main/java/ru/dmitriymx/skeleton/springmvc/SpringConfigMVC.java +++ b/src/main/java/ru/dmitriymx/skeleton/springmvc/SpringConfigMVC.java @@ -6,7 +6,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.thymeleaf.TemplateEngine; import org.thymeleaf.spring4.SpringTemplateEngine; import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver; @@ -19,7 +19,7 @@ import org.thymeleaf.templateresolver.ITemplateResolver; */ @Configuration @EnableWebMvc -public class SpringConfigMVC extends WebMvcConfigurerAdapter{ +public class SpringConfigMVC implements WebMvcConfigurer { @Autowired private ApplicationContext applicationContext; diff --git a/src/main/java/ru/dmitriymx/skeleton/springmvc/WebApp.java b/src/main/java/ru/dmitriymx/skeleton/springmvc/WebApp.java index 80efcf6..a700f5e 100644 --- a/src/main/java/ru/dmitriymx/skeleton/springmvc/WebApp.java +++ b/src/main/java/ru/dmitriymx/skeleton/springmvc/WebApp.java @@ -14,8 +14,8 @@ import org.springframework.web.servlet.DispatcherServlet; import java.net.InetSocketAddress; -@RequiredArgsConstructor @Slf4j +@RequiredArgsConstructor public class WebApp { private final String host; private final int port; @@ -65,20 +65,9 @@ public class WebApp { } } - /** - * Для запуска можно указать два параметра: хост и порт. - * По-умолчанию: 127.0.0.1:8080 - * - * @param args параметры запуска - */ public static void main(String[] args) { - String host = "127.0.0.1"; - int port = 8080; - - if (args.length == 2) { - host = args[0]; - port = Integer.parseInt(args[1]); - } + final String host = System.getProperty("host", "127.0.0.1"); + final int port = Integer.parseInt(System.getProperty("port", "8080")); log.info("Web app listen: {}:{}", host, port); WebApp app = new WebApp(host, port); diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..3be0d2c --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + +