Versiones comparadas

Clave

  • Se ha añadido esta línea.
  • Se ha eliminado esta línea.
  • El formato se ha cambiado.

...

Bloque de código
languagexml
	<dependencies>
		<!-- JWT -->
		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt</artifactId>
			<version>0.9.1</version>
		</dependency>

		<!-- Data JPA -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- Hibernate -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-jpamodelgen</artifactId>
			<version>5.4.12.Final</version>
			<scope>provided</scope>
		</dependency>

		<!-- Real DB -->
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>jdbc.driver</artifactId>
			<version>11.2.0.3.0</version>
		</dependency>

		<!-- UNDERTOW -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
 			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starte-logging</artifactId>
				</exclusion>
 				<exclusion>
 					<groupId>org.springframework.boot</groupId>
 					<artifactId>spring-boot-starter-tomcat</artifactId>
 				</exclusion>
 				<exclusion>
 					<groupId>org.springframework.boot</groupId>
 					<artifactId>spring-boot-starter-logging</artifactId>
 				</exclusion>
 			</exclusions>
		</dependency>

 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-undertow</artifactId>
 			<exclusions>
 				<exclusion>
 					<groupId>org.springframework.boot</groupId>
 					<artifactId>spring-boot-starter-logging</artifactId>
 				</exclusion>
 			</exclusions>
 		</dependency>

		<!-- SECURITY -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- TEST -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starte-logging</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- Test DB -->
		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
			<scope>test</scope>
		</dependency>

		<!-- Selenium -->
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<!-- <version>3.141.59</version> -->
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
		</dependency>

		<!-- Log4j2 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-log4j2</artifactId>
		</dependency>

		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-layout-template-json</artifactId>
			<version>2.14.0</version>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- frontLogger -->
		<dependency>
			<groupId>es.um.atica.fundewebjs.fundewebjs-api</groupId>
			<artifactId>fundewebjs-lagar</artifactId>
			<version>1.0.0-SNAPSHOT</version>
		</dependency>

		<!-- Lombok -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>

	</dependencies>

	<repositories>
		<repository>
			<id>archiva.atica.umu.es</id>
			<name>ATICA - UMU Repository</name>
			<url>https://archiva.um.es/archiva/repository/FundeWeb/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>
	<repository>
	<build>
		<plugins><id>fundewebjs.archiva.atica.umu.es</id>
			<plugin><name>ATICA - UMU Repository - FundeWebJS</name>
				<groupId>org.springframework.boot</groupId><url>https://archiva.um.es/archiva/repository/FundeWebJS/</url>
			<releases>
				<artifactId>spring-boot-maven-plugin</artifactId><enabled>true</enabled>
			</plugin>releases>
			<plugin><snapshots>
				<groupId>org.hibernate.orm.tooling</groupId><enabled>true</enabled>
				<artifactId>hibernate-enhance-maven-plugin</artifactId>
				<version>${hibernate.version}</version>
				<executions></snapshots>
		</repository>  </repositories>

	<build>
		<plugins>
					<execution><plugin>
						<configuration><groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			<failOnError>true<</failOnError>plugin>
			<plugin>
				<enableLazyInitialization>true</enableLazyInitialization>
<groupId>org.hibernate.orm.tooling</groupId>
				<artifactId>hibernate-enhance-maven-plugin</artifactId>
				<enableDirtyTracking>true</enableDirtyTracking><version>${hibernate.version}</version>
				<executions>
			<enableAssociationManagement>true</enableAssociationManagement>		<execution>
						<configuration>
	<enableExtendedEnhancement>false</enableExtendedEnhancement>
						<<failOnError>true</configuration>failOnError>
						<goals>	<enableLazyInitialization>true</enableLazyInitialization>
							<goal>enhance<<enableDirtyTracking>true</goal>enableDirtyTracking>
						<	<enableAssociationManagement>true</goals>enableAssociationManagement>
							<<enableExtendedEnhancement>false</execution>enableExtendedEnhancement>
						</executions>configuration>
						<goals>
							<goal>enhance</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<!-- JaCoCo configuration -->
			<plugin>
				<groupId>org.jacoco</groupId>
				<artifactId>jacoco-maven-plugin</artifactId>
				<version>0.7.7.201606060606</version>
				<executions>
					<execution>
						<goals>
							<goal>prepare-agent</goal>
						</goals>
					</execution>
					<execution>
						<id>report</id>
						<phase>prepare-package</phase>
						<goals>
							<goal>report</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<!-- Enunciate -->
			<plugin>
				<groupId>com.webcohesion.enunciate</groupId>
				<artifactId>enunciate-maven-plugin</artifactId>
				<version>2.13.0</version>
				<dependencies>
					<dependency>
						<groupId>com.webcohesion.enunciate</groupId>
						<artifactId>enunciate-lombok</artifactId>
						<version>2.9.1</version>
					</dependency>
				</dependencies>
				<executions>
					<execution>
						<id>fdwjs</id>
						<configuration>
							<docsDir>${basedir}/src/main/resources/</docsDir>
							<docsSubdir>static/docs/</docsSubdir>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<!-- FIN Enunciate -->

		</plugins>
	</build>

...

Bloque de código
########## RUTA BASE REST ##########
server.servlet.context-path=/api

########## BASE DE DATOS ##########
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.ddl-auto = validate
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

spring.datasource.url=jdbc:oracle:thin:@hydra-prescan.atica.um.es:1526/ZEUSDESA
spring.datasource.username=USER
spring.datasource.password=PASSWORD

Si queremos cambiar el puerto que utiliza nuestra aplicación, que por defecto es el 8080, podemos hacerlo con la propiedad server.port. Otras propiedades que haya que definirse para otras funcionalidades, como para el login, se incluyen en su página de documentación correspondiente. Si queremos ver las propiedades de configuración que ofrece Spring podemos consultarlas aquí.

log4j2.xml

Debemos crear el fichero log4j2.xml en la carpeta /src/main/resources con el siguiente contenido:


 
########## FRONT-LOGGER ##########
# FundeWebJS Habilitar endpoint jsn.logger
fdwjs.api.frontLogger.enable=true

# FundeWebJS Habilitar filtro para cabeceras en logs MDC de lagar 
fdwjs.api.lagar.enable=true 
fdwjs.api.lagar.headers=UMU-User-UUID,UMU-Client-APP

# FundeWebJS Habilitar filtro para loggear request/response
fdwjs.api.logging.enable=true
fdwjs.api.logging.client.enable=true
fdwjs.api.logging.query.enable=true
fdwjs.api.logging.headers.enable=true
fdwjs.api.logging.payload.enable=true
fdwjs.api.logging.payload.maxLength=6400
fdwjs.api.logging.url-patterns=*

Si queremos cambiar el puerto que utiliza nuestra aplicación, que por defecto es el 8080, podemos hacerlo con la propiedad server.port. Otras propiedades que haya que definirse para otras funcionalidades, como para el login, se incluyen en su página de documentación correspondiente. Si queremos ver las propiedades de configuración que ofrece Spring podemos consultarlas aquí.

log4j2.xml

Debemos crear el fichero log4j2.xml en la carpeta /src/main/resources con el siguiente contenido:

Bloque de código
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorinterval="60" >
    <Properties>
        <Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
        <Property name="LOG_LEVEL_PATTERN">%5p</Property>
        <Property name="LOG_DATEFORMAT_PATTERN">dd-MM-yyyy HH:mm:ss.SSS</Property>
        <Property name="CONSOLE_LOG_PATTERN">%d{${LOG_DATEFORMAT_PATTERN}} ${LOG_LEVEL_PATTERN} ${sys:PID} --- [%t] %-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
    </Properties>
    <Appenders>
        <Console name="local" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" />
        </Console>
         
        <Console name="json" target="SYSTEM_OUT" follow="true">
            <JsonTemplateLayout eventTemplateUri="classpath:LogstashJsonEventLayoutV1.json" locationInfoEnabled="true" stackTraceEnabled="true"/>
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
        <Logger name="org.apache.catalina.util.LifecycleBase" level="error" />
        <Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
        <logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
        <Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
        <Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error" />
        <Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
        <logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
Bloque de código
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorinterval="60" >
    <Properties>
        <Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
        <Property name="LOG_LEVEL_PATTERN">%5p</Property>
        <Property name="LOG_DATEFORMAT_PATTERN">dd-MM-yyyy HH:mm:ss.SSS</Property>
        <Property name="CONSOLE_LOG_PATTERN">%d{${LOG_DATEFORMAT_PATTERN}} ${LOG_LEVEL_PATTERN} ${sys:PID} --- [%t] %-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
    </Properties>
    <Appenders>
        <Console name="local" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" />
        </Console>
         
        <Console<Root namelevel="json" target="SYSTEM_OUT" follow="true"debug">
            <JsonTemplateLayout<AppenderRef eventTemplateUriref="classpath:LogstashJsonEventLayoutV1.json" locationInfoEnabled="true" stackTraceEnabled="true"local" />
        </Console>Root>
    </Appenders>
    <Loggers>
        <Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
        <Logger name="org.apache.catalina.util.LifecycleBase" level="error" />
        <Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
        <logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
        <Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
        <Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error" />
        <Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
        <logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
        <Root level="debug">
            <AppenderRef ref="local" />
        </Root>
    </Loggers>
</Configuration>

...

Loggers>
</Configuration>

Este es un archivo de configuración para los logs, que vienen explicados más detalladamente en esta página.

Clase inicial de la aplicación

En la clase que inicia la aplicación, que será algo como NombreApplication.java, sustituyendo Nombre por el de nuestra aplicación, tendremos que añadir a la clase la anotación @ComponentScan, con el contenido siguiente:

Bloque de código
languagejava
@ComponentScan( basePackages = {
		"es.um.atica.aplicacion", "es.um.atica.fundewebjs"
} )

Ahí, tenemos que cambiar aplicación por el paquete base de nuestra aplicación.

Con esto, un ejemplo de esta clase inicial podría ser el siguiente:

Bloque de código
languagejava
package es.um.atica.pruebaspose;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan( basePackages = {
		"es.um.atica.pruebaspose", "es.um.atica.fundewebjs"
} )
public class PruebasPoseApplication {

	public static void main(String[] args) {
		SpringApplication.run(PruebasPoseApplication.class, args);
	}

}

WebSecurity

Por otro lado, nos haremos una clase java para especificar la configuración de seguridad web, que debe extender a WebSecurityConfigurerAdapter e incluir la anotación @EnableWebSecurity:

...