Kum*_*hav 5 postgresql spring-batch spring-boot
我正在尝试使用 PosgreSQL 作为数据库的普通 Spring 批处理应用程序。
pom.xml:-
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.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.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
<exclusions>
<exclusion>
<artifactId>hsqldb</artifactId>
<groupId>org.hsqldb</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我已明确排除“hsqldb”以确保 Spring 批处理使用 posgres。添加此依赖项可以解决问题,但我不想在我的设置中使用 hsqldb。
配置等级:-
@SpringBootApplication
@EnableBatchProcessing
public class Application {
private static Logger LOG = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序.yml
spring:
application:
name: theapp
batch:
job:
enabled: false
profiles:
active: local
---
spring:
profiles: local
data:
mongodb:
host: localhost
database: dbname
datasource:
username: postgres
password: password
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/org.postgresql.Driver
---
spring:
profiles: abc
data:
mongodb:
database: dbname
host: abc.com
datasource:
username: postgres
password: password
url: jdbc:postgresql://abc.com:5432/dbname
driver-class-name: org.postgresql.Driver
Run Code Online (Sandbox Code Playgroud)
Junit 类:-
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { Application.class })
@ActiveProfiles(profiles = { "local" })
public class BillingEngineBatchTest {
@Test
public void test() {
Assert.assertNotNull("");
}
}
Run Code Online (Sandbox Code Playgroud)
如何告诉 Spring Batch 使用 postgres 而不是嵌入式数据库?
在应用程序启动期间,我收到一条异常消息:“原因是:org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE."
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "local" are currently active).
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 77 more
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "local" are currently active).
Run Code Online (Sandbox Code Playgroud)
如果你使用 postgres 那么你可能需要这个pom.xml:
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我希望这可以解决你的问题
| 归档时间: |
|
| 查看次数: |
2827 次 |
| 最近记录: |