Merge branch 'master' into thymeleaf
# Conflicts: # src/main/java/ru/dmitriymx/skeleton/springmvc/WebApp.java
This commit is contained in:
22
README.MD
Normal file
22
README.MD
Normal 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
60
pom.xml
@@ -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 -->
|
||||
@@ -69,7 +77,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</version>
|
||||
<version>1.18.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.thymeleaf</groupId>
|
||||
@@ -85,7 +93,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>
|
||||
@@ -95,11 +103,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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
13
src/main/resources/log4j2.xml
Normal file
13
src/main/resources/log4j2.xml
Normal 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>
|
||||
Reference in New Issue
Block a user