Upgrade to @SpringBootApplication

This commit is contained in:
Greg Turnquist
2015-02-24 15:18:43 -06:00
parent 50d2b0dcdb
commit cee9eabde2
6 changed files with 22 additions and 46 deletions
+15 -9
View File
@@ -4,21 +4,27 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
@ComponentScan
@EnableAutoConfiguration
public class Application {
@SpringBootApplication
public class Application implements CommandLineRunner {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
SpringApplication.run(Application.class, args);
}
List<Person> results = ctx.getBean(JdbcTemplate.class).query("SELECT first_name, last_name FROM people", new RowMapper<Person>() {
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public void run(String... strings) throws Exception {
List<Person> results = jdbcTemplate.query("SELECT first_name, last_name FROM people", new RowMapper<Person>() {
@Override
public Person mapRow(ResultSet rs, int row) throws SQLException {
return new Person(rs.getString(1), rs.getString(2));
@@ -28,6 +34,6 @@ public class Application {
for (Person person : results) {
System.out.println("Found <" + person + "> in the database.");
}
}
}
}