click derecho -> new -> project -> Maven Project
2) Configurar el Build Path del Proyecto
click derecho sobre el proyecto -> Build path -> Configure Build path
asignar el JRE correcto.
asignar el Server correcto.
3) Agregar las dependencias necesarias en el archivo pom.xml
[code]
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cmd.cc</groupId>
<artifactId>mailingwebapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>mailingwebapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
[/code]
luego de salvar estos cambios, posiblemente te salga el siguiente error:
esto se soluciona facilmente
click derecho sobre el proyecto -> maven -> Update project
click en [OK]
4) Crear los modelos con los que se trabajará
en src/main/java creamos el package com.cmd.cc.domain
y en él crear el modelo MailingFilter.java
[code]
package com.cmd.cc.domain;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class MailingFilter {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
[/code]
5) Spring Data JPA Repository
Creamos el package com.cmd.cc.repositories
y en el la interface MailingFilterRepository.java
[code] package com.cmd.cc.repositories; import org.springframework.data.repository.CrudRepository; import com.cmd.cc.domain.MailingFilter; public interface MailingFilterRepository extends CrudRepository<MailingFilter, Integer>{ } [/code]
6) Implementar Spring Facade service.
Creamos un servicio que será quien interactue con la capa de persistencia.
en src/main/java creamos el package com.cmd.cc.services
y en él creamos primero una interface llamada MailingFilterService.java
[code]
package com.cmd.cc.services;
import com.cmd.cc.domain.MailingFilter;
public interface MailingFilterService {
Iterable<MailingFilter> listAllMailingFilters();
MailingFilter getMailingFilterById(Integer id);
MailingFilter saveMailingFilter(MailingFilter mailingFilter);
void deleteMailingFilter(Integer id);
}
[/code]
en ese mismo package crear la clase que implementa la interface la llamamos MailingFilterServiceImpl.java
[code]
package com.cmd.cc.services;
import org.springframework.beans.factory.annotation.Autowired;
import com.cmd.cc.domain.MailingFilter;
import com.cmd.cc.repositories.MailingFilterRepository;
public class MailingFilterServiceImpl implements MailingFilterService {
private MailingFilterRepository mailingfilterRepository;
@Autowired
public void setMailingFilterRepository(MailingFilterRepository mailingfilterRepository) {
this.mailingfilterRepository = mailingfilterRepository;
}
@Override
public Iterable<MailingFilter> listAllMailingFilters() {
// TODO Auto-generated method stub
return mailingfilterRepository.findAll();
}
@Override
public MailingFilter getMailingFilterById(Integer id) {
// TODO Auto-generated method stub
return mailingfilterRepository.findOne(id);
}
@Override
public MailingFilter saveMailingFilter(MailingFilter mailingFilter) {
// TODO Auto-generated method stub
return mailingfilterRepository.save(mailingFilter);
}
@Override
public void deleteMailingFilter(Integer id) {
// TODO Auto-generated method stub
mailingfilterRepository.delete(id);
}
}
[/code]