0

Merge branch 'master' into freemarker

# Conflicts:
#	src/main/java/ru/dmitriymx/skeleton/springmvc/WebApp.java
This commit is contained in:
2018-09-23 14:40:38 +03:00
5 changed files with 90 additions and 26 deletions

22
README.MD Normal file
View File

@@ -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`

60
pom.xml
View File

@@ -7,14 +7,17 @@
<groupId>ru.dmitriymx.skeleton</groupId>
<artifactId>spring-mvc</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<slf4j.version>1.7.21</slf4j.version>
<spring.version>4.2.5.RELEASE</spring.version>
<jetty.version>9.4.0.v20161208</jetty.version>
<slf4j.version>1.7.25</slf4j.version>
<log4j.version>2.11.1</log4j.version>
<spring.version>5.1.0.RELEASE</spring.version>
<jetty.version>9.4.12.v20180830</jetty.version>
<dependencies.dir>lib</dependencies.dir>
<main.class>ru.dmitriymx.skeleton.springmvc.WebApp</main.class>
</properties>
<dependencies>
@@ -30,9 +33,14 @@
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- SPRING -->
@@ -74,7 +82,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<version>1.18.2</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
@@ -89,7 +97,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.8.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -99,11 +107,43 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<version>2.22.0</version>
<configuration>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${dependencies.dir}/</classpathPrefix>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<outputDirectory>${project.build.directory}/${dependencies.dir}/</outputDirectory>
<excludeScope>provided</excludeScope>
</configuration>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -4,7 +4,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.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
@@ -13,7 +13,7 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
*/
@Configuration
@EnableWebMvc
public class SpringConfigMVC extends WebMvcConfigurerAdapter {
public class SpringConfigMVC implements WebMvcConfigurer {
/**
* Компонент, отвечающий за отображение шаблонов
*

View File

@@ -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);

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%level] (%t) \{%logger\} %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>