├── .gitignore
├── README.md
├── pom.xml
└── src
└── main
├── java
└── com
│ └── test
│ └── so
│ ├── DialerApplication.java
│ ├── common
│ └── ApplicationDataSource.java
│ ├── controller
│ └── MainController.java
│ ├── domain
│ └── PhoneSettings.java
│ ├── repository
│ └── PhoneSettingsRepository.java
│ └── service
│ ├── PhoneSettingsService.java
│ └── impl
│ └── PhoneSettingsServiceImpl.java
└── resources
├── application.properties
└── logback.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.idea
2 | *.iml
3 | *.db
4 | target/
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### A SpringBoot Application with BoneCP
2 |
3 | Demonstrates how to set up a connection pool with [BoneCP](https://github.com/wwadge/bonecp) in a SpringBoot application.
4 |
5 | ### To run the application
6 | `mvn clean package && java -jar target/springbootbonecpds.jar`
7 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.test.so
8 | springbootbonecpds
9 | 1.0-SNAPSHOT
10 | jar
11 |
12 |
13 | org.springframework.boot
14 | spring-boot-starter-parent
15 | 1.2.0.RELEASE
16 |
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | commons.logging
26 | commons-logging
27 |
28 |
29 |
30 |
31 |
32 | org.slf4j
33 | slf4j-api
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-data-jpa
39 |
40 |
41 |
42 | com.jolbox
43 | bonecp
44 | 0.8.0.RELEASE
45 |
46 |
47 |
48 | com.h2database
49 | h2
50 | 2.1.210
51 |
52 |
53 |
54 |
55 |
56 | ${project.artifactId}
57 |
58 |
59 | org.springframework.boot
60 | spring-boot-maven-plugin
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/src/main/java/com/test/so/DialerApplication.java:
--------------------------------------------------------------------------------
1 | package com.test.so;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
7 | import org.springframework.context.annotation.ComponentScan;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
10 | import org.springframework.transaction.annotation.EnableTransactionManagement;
11 |
12 | /**
13 | * Created by azizunsal on 24/02/15.
14 | */
15 | @Configuration
16 | @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
17 | @ComponentScan
18 | @SpringBootApplication
19 | @EnableTransactionManagement
20 | @EnableJpaRepositories
21 | public class DialerApplication {
22 |
23 | public static void main(String[] args) {
24 | SpringApplication.run(DialerApplication.class, args);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/test/so/common/ApplicationDataSource.java:
--------------------------------------------------------------------------------
1 | package com.test.so.common;
2 |
3 | import com.jolbox.bonecp.BoneCPDataSource;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.context.annotation.PropertySource;
8 | import org.springframework.core.env.Environment;
9 |
10 | import javax.sql.DataSource;
11 |
12 | /**
13 | * Created by azizunsal on 24/02/15.
14 | */
15 |
16 | @Configuration
17 | @PropertySource("classpath:application.properties")
18 | public class ApplicationDataSource {
19 |
20 | @Autowired
21 | private Environment environment;
22 |
23 | @Bean
24 | public DataSource dataSource() {
25 | BoneCPDataSource dataSource = new BoneCPDataSource();
26 | dataSource.setDriverClass(environment.getRequiredProperty("spring.datasource.driverClassName"));
27 | dataSource.setJdbcUrl(environment.getRequiredProperty("spring.datasource.url"));
28 | dataSource.setUsername(environment.getRequiredProperty("spring.datasource.username"));
29 | dataSource.setPassword(environment.getRequiredProperty("spring.datasource.password"));
30 | return dataSource;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/test/so/controller/MainController.java:
--------------------------------------------------------------------------------
1 | package com.test.so.controller;
2 |
3 | import com.test.so.service.PhoneSettingsService;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestMethod;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | /**
13 | * Created by azizunsal on 24/02/15.
14 | */
15 |
16 | @RestController
17 | @RequestMapping("/")
18 | public class MainController {
19 |
20 | @Autowired
21 | private PhoneSettingsService phoneSettingsService;
22 |
23 | private static final Logger logger = LoggerFactory.getLogger(MainController.class);
24 |
25 | @RequestMapping(method = RequestMethod.GET)
26 | public String test() {
27 | logger.info("Hello controller - test");
28 | return "Hello Controller - Test";
29 | }
30 |
31 | @RequestMapping(value = "/{id}", method = RequestMethod.GET)
32 | public String testById(@PathVariable Long id) {
33 | logger.info("Hello controller - test by id {}", id);
34 | return "Hello Controller - Test By Id";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/test/so/domain/PhoneSettings.java:
--------------------------------------------------------------------------------
1 | package com.test.so.domain;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.Id;
5 | import javax.persistence.Table;
6 |
7 | /**
8 | * Created by azizunsal on 24/02/15.
9 | */
10 | @Entity
11 | @Table(name = "phone_settings", catalog = "dialer")
12 | public class PhoneSettings implements java.io.Serializable {
13 |
14 | @Id
15 | private Long id;
16 | private String name;
17 |
18 | public Long getId() {
19 | return id;
20 | }
21 |
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return "PhoneSettings{" +
37 | "id=" + id +
38 | ", name='" + name + '\'' +
39 | '}';
40 | }
41 | }
--------------------------------------------------------------------------------
/src/main/java/com/test/so/repository/PhoneSettingsRepository.java:
--------------------------------------------------------------------------------
1 | package com.test.so.repository;
2 |
3 | import com.test.so.domain.PhoneSettings;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | /**
8 | * Created by azizunsal on 24/02/15.
9 | */
10 |
11 | @Repository
12 | public interface PhoneSettingsRepository extends JpaRepository {
13 |
14 | }
--------------------------------------------------------------------------------
/src/main/java/com/test/so/service/PhoneSettingsService.java:
--------------------------------------------------------------------------------
1 | package com.test.so.service;
2 |
3 |
4 | import com.test.so.domain.PhoneSettings;
5 |
6 | /**
7 | * Created by azizunsal on 24/02/15.
8 | */
9 | public interface PhoneSettingsService {
10 | PhoneSettings findById(Long id);
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/test/so/service/impl/PhoneSettingsServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.test.so.service.impl;
2 |
3 | import com.test.so.domain.PhoneSettings;
4 | import com.test.so.repository.PhoneSettingsRepository;
5 | import com.test.so.service.PhoneSettingsService;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Service;
10 |
11 | /**
12 | * Created by azizunsal on 24/02/15.
13 | */
14 | @Service
15 | public class PhoneSettingsServiceImpl implements PhoneSettingsService {
16 |
17 | private static final Logger logger = LoggerFactory.getLogger(PhoneSettingsServiceImpl.class);
18 |
19 | @Autowired
20 | private PhoneSettingsRepository phoneSettingsRepository;
21 |
22 | @Override
23 | public PhoneSettings findById(Long id) {
24 | logger.info("Find by id {}", id);
25 | return phoneSettingsRepository.findOne(id);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8088
2 |
3 | # DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
4 | spring.datasource.driverClassName=org.h2.Driver
5 | spring.datasource.url=jdbc:h2:./test-db
6 | spring.datasource.username=sa
7 | spring.datasource.password=
8 |
9 | # JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
10 | spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
11 | spring.jpa.show-sql=true
--------------------------------------------------------------------------------
/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------