added source for 'A Guide to Spring Boot in Eclipse'

This commit is contained in:
Julius Krah 2016-07-06 16:09:24 +00:00
parent 024b4f8f61
commit fff769ed9d
8 changed files with 204 additions and 59 deletions

View File

@ -1 +1,4 @@
/target/ /target/
.settings/
.classpath
.project

View File

@ -1,73 +1,97 @@
<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/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.baeldung</groupId> <modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot</artifactId> <groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version> <artifactId>spring-boot</artifactId>
<packaging>war</packaging> <version>0.0.1-SNAPSHOT</version>
<name>Spring Boot Actuator</name> <packaging>war</packaging>
<description>This is simple boot application for Spring boot actuator test</description> <name>Spring Boot Actuator</name>
<description>This is simple boot application for Spring boot actuator test</description>
<!-- Inherit defaults from Spring Boot --> <!-- Inherit defaults from Spring Boot -->
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version> <version>1.3.6.RELEASE</version>
</parent> <relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies> <properties>
<dependency> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<groupId>org.springframework.boot</groupId> <java.version>1.8</java.version>
<artifactId>spring-boot-starter-web</artifactId> <!-- <spring.version>4.3.0.RELEASE</spring.version> -->
</dependency> </properties>
<dependency> <dependencies>
<groupId>org.springframework.boot</groupId> <dependency>
<artifactId>spring-boot-starter-actuator</artifactId> <groupId>org.springframework.boot</groupId>
</dependency> <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.dropwizard.metrics</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>metrics-core</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
</dependencies>
<build> <dependency>
<finalName>spring-boot</finalName> <groupId>org.springframework.boot</groupId>
<resources> <artifactId>spring-boot-starter-security</artifactId>
<resource> </dependency>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins> <dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
<plugin> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>com.h2database</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>h2</artifactId>
</plugin> </dependency>
<plugin> <dependency>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<configuration> <scope>test</scope>
<source>1.8</source> </dependency>
<target>1.8</target> </dependencies>
</configuration>
</plugin>
<plugin> <build>
<groupId>org.apache.maven.plugins</groupId> <finalName>spring-boot</finalName>
<artifactId>maven-war-plugin</artifactId> <resources>
</plugin> <resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</plugins> <plugins>
</build> <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -0,0 +1,13 @@
package org.baeldung.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
System.setProperty("spring.config.name", "demo");
SpringApplication.run(DemoApplication.class, args);
}
}

View File

@ -0,0 +1,40 @@
package org.baeldung.boot.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Foo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Integer id;
private String name;
public Foo() {
}
public Foo(String name) {
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,8 @@
package org.baeldung.boot.repository;
import org.baeldung.boot.model.Foo;
import org.springframework.data.jpa.repository.JpaRepository;
public interface FooRepository extends JpaRepository<Foo, Integer> {
public Foo findByName(String name);
}

View File

@ -0,0 +1,6 @@
spring.output.ansi.enabled=never
server.port=7070
# Security
security.user.name=admin
security.user.password=password

View File

@ -0,0 +1,18 @@
package org.baeldung.boot;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = DemoApplication.class)
@WebAppConfiguration
public class DemoApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@ -0,0 +1,33 @@
package org.baeldung.boot.repository;
import static org.junit.Assert.assertThat;
import org.baeldung.boot.DemoApplicationTests;
import org.baeldung.boot.model.Foo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.is;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public class FooRepositoryTest extends DemoApplicationTests {
@Autowired
private FooRepository fooRepository;
@Before
public void setUp() {
fooRepository.save(new Foo("Foo"));
fooRepository.save(new Foo("Bar"));
}
@Test
public void testFindByName() {
Foo foo = fooRepository.findByName("Bar");
assertThat(foo, notNullValue());
assertThat(foo.getId(), is(2));
}
}