복붙노트

[SPRING] spring.datasource.type을 설정할 수 없습니다.

SPRING

spring.datasource.type을 설정할 수 없습니다.

스프링 부트 서버에 c3p0을 설치하려고합니다. 이건 내 설정이야.

spring.datasource.url=jdbc:mysql://url/db
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.test-on-borrow=true
#spring.datasource.test-while-idle=true
spring.datasource.validation-query=SELECT 1
#spring.datasource.time-between-eviction-runs-millis=10000
#spring.datasource.min-evictable-idle-time-millis=30000

spring.jpa.show-sql=true

spring.jpa.properties.hibernate.globally_quoted_identifiers=true
spring.jpa.properties.hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
spring.jpa.properties.hibernate.connection.driver_class=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.connection.url=jdbc:mysql://url/db
spring.jpa.properties.hibernate.connection.username=username
spring.jpa.properties.hibernate.connection.password=password
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.show_sql=true
#spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop


spring.jpa.properties.hibernate.c3p0.max_size=30
spring.jpa.properties.hibernate.c3p0.min_size=7
spring.jpa.properties.hibernate.c3p0.acquire_increment=1
spring.jpa.properties.hibernate.c3p0.idle_test_period=100
spring.jpa.properties.hibernate.c3p0.max_statements=0
spring.jpa.properties.hibernate.c3p0.max_idle_time=200
spring.jpa.properties.hibernate.c3p0.url=jdbc:mysql://url/db
spring.jpa.properties.hibernate.c3p0.username=username
spring.jpa.properties.hibernate.c3p0.password=password
spring.jpa.properties.hibernate.c3p0.driverClassName=com.mysql.jdbc.Driver

내 문제는 내가 spring.datasource에게 사용하는 방법을 알아낼 수 없다는 것이다.

com.mchange.v2.c3p0.ComboPooledDataSource

내가 본 모든 XML 정의는

<bean id="dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource">

application.properties에 데이터 소스 유형 / 클래스를 설정할 수 있습니까?

이에 따르면

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

있다

spring.datasource.type= # fully qualified name of the connection pool implementation to use

그러나 이것에 따르면

http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

(그리고 내 STS) .type 옵션이 존재하지 않습니다. 이 버그입니까, 아니면 다른 방식으로 사용해야합니까?

귀하의 도움을 많이 부탁드립니다!

건배!

해결법

  1. ==============================

    1.spring.datasource.type이 1.3 라인에서 소개되었으므로 Spring Boot 1.3.0.M5를 사용하여 해당 등록 정보를 사용하십시오 (IDE의 컨텐츠 지원이 올바른 힌트를 제공해야 함).

    spring.datasource.type이 1.3 라인에서 소개되었으므로 Spring Boot 1.3.0.M5를 사용하여 해당 등록 정보를 사용하십시오 (IDE의 컨텐츠 지원이 올바른 힌트를 제공해야 함).

    1.2.x에서는 타입을 강제로 만들기 위해 DataSource bean을 생성해야합니다.

    @Bean
    @ConfigurationProperties("spring.datasource")
    public DataSource dataSource() {
       return DataSourceBuilder.create().type(ComboPooledDataSource.class)
                .build();
    }
    
  2. ==============================

    2.너희들 머리에 못을 박았다. 오늘 아침에 수동 설치 구성을하고 c3p0을 연결했지만 jdbcTemplate을 사용하고있는 컨트롤러 중 하나에 대해 c3p0 데이터 소스를 jdbcTemplates와 사용할 수 없으므로 대안을 살펴 보았습니다.

    너희들 머리에 못을 박았다. 오늘 아침에 수동 설치 구성을하고 c3p0을 연결했지만 jdbcTemplate을 사용하고있는 컨트롤러 중 하나에 대해 c3p0 데이터 소스를 jdbcTemplates와 사용할 수 없으므로 대안을 살펴 보았습니다.

    나는 약간의 독서를했고 그것은 tomcat-jdbc 풀이 나의 경우를위한 최선의 선택 일 것이라고 판명했다. 그래서 이것을 설정하기 위해 원래의 게시물에 나열된 application.properties에서 모든 속성을 제거하고 다음 사용자 정의 속성을 추가했습니다.

    tomcat.jdbc.pool.url=jdbc:mysql://url/db_name
    tomcat.jdbc.pool.username=username
    tomcat.jdbc.pool.password=password
    tomcat.jdbc.pool.initial-size=10
    tomcat.jdbc.pool.test-on-borrow=true
    tomcat.jdbc.pool.test-while-idle=true
    tomcat.jdbc.pool.validation-query=SELECT 1
    tomcat.jdbc.pool.driver-class-name=com.mysql.jdbc.Driver
    tomcat.jdbc.pool.max_size=30
    tomcat.jdbc.pool.min_size=7
    

    그런 다음 기본 데이터 소스를 org.apache.tomcat.jdbc.pool.DataSource로 설정하기 위해 다음 구성 클래스를 만들었습니다.

    import org.apache.tomcat.jdbc.pool.DataSource;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Primary;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    
    
    @EnableTransactionManagement
    @Configuration
    public class DataSourceConfiguration {
    
        @Value("${tomcat.jdbc.pool.max_size}")
        private int maxSize;
    
        @Value("${tomcat.jdbc.pool.min_size}")
        private int minSize;
    
        @Value("${tomcat.jdbc.pool.initial-size}")
        private int initialSize;
    
        @Value("${tomcat.jdbc.pool.test-on-borrow}")
        private boolean testOnBorrow;
    
        @Value("${tomcat.jdbc.pool.test-while-idle}")
        private boolean testWhileIdle;
    
        @Value("${tomcat.jdbc.pool.username}")
        private String username;
    
        @Value("${tomcat.jdbc.pool.password}")
        private String password;
    
        @Value("${tomcat.jdbc.pool.url}")
        private String url;
    
        @Value("${tomcat.jdbc.pool.driver-class-name}")
        private String driverClassName;
    
        @Value("${tomcat.jdbc.pool.validation-query}")
        private String validationQuery;
    
        @Bean
        @Primary
        public DataSource dataSource() {
            DataSource dataSource = new DataSource();
            dataSource.setUrl(url);
            dataSource.setPassword(password);
            dataSource.setUsername(username);
            dataSource.setDriverClassName(driverClassName);
            dataSource.setValidationQuery(validationQuery);
            dataSource.setInitialSize(initialSize);
            dataSource.setMaxIdle(maxSize);
            dataSource.setMinIdle(minSize);
            dataSource.setTestOnBorrow(testOnBorrow);
            dataSource.setTestWhileIdle(testWhileIdle);
            return dataSource;
        }
    }
    

    그리고 이제, 생산 준비가 된 연결 풀이 생겼습니다.

    나는 HikariCP가 아마도 tomcat-jdbc보다 뛰어난 성능을 보일 것이라고 읽었지 만, 내 응용 프로그램은 비즈니스에서 제공하는 사용자 정의 요청이므로 한 번에 5-10-20 명의 사용자 만 사용할 수 있으므로 구성 및 설정의 용이함이 확실히 적은 성능을 능가합니다 이익.

    희망이 사람을 도움이됩니다.

  3. from https://stackoverflow.com/questions/32833641/not-able-to-set-spring-datasource-type by cc-by-sa and MIT license