我正在尝试使用注释配置在Spring Boot中配置Postgres数据库。我将所有数据库凭据存储在名为database.properties
的文件中,并将配置文件称为DBconfig.java
database.url= jdbc:postgresql://localhost/mydb
database.driverClassName= com.postgresql.jdbc.Driver
database.username= postgres
database.password= password
dbConfig文件-
@Configuration
@PropertySource("classpath:databaseAccess/database.properties")
public class DBconfig {
@Value("${username}")
private String username;
@Value("${password}")
private String password;
@Value("${url}")
private String url;
@Bean
@Qualifier("postgresDB")
public DataSource dataSource() {
DataSourceBuilder dataSource = DataSourceBuilder.create();
dataSource.url(url);
dataSource.password(password);
//dataSource.driverClassName(driverClassName);
dataSource.username(username);
return dataSource.build();
}
@Bean
@Qualifier("jdbcTemplate")
public JdbcTemplate jdbcTemplate() {
return new JdbcTemplate(dataSource());
}
}
这是我的主文件
@SpringBootApplication
public class GetNotificationsApplication {
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(DBconfig.class);
JdbcTemplate template= ctx.getBean("jdbcTemplate", JdbcTemplate.class);
template.execute("CREATE TABLE TEST( test VARCHAR(20))");
}
}
我不断收到错误消息 工厂方法'dataSource'抛出异常;嵌套异常是java.lang.IllegalArgumentException:URL必须以'jdbc'开头
答案 0 :(得分:0)
尝试通过定义postgres的端口号来更改url参数的值。假设postgres在5432上运行,这是默认端口。
更改
Uncaught (in promise): Error: Cannot find module '../webcomponents/item.js'
收件人
Warnings while compiling
...
Critical dependency: the request of a dependency is an expression
有关端口号,请检查Find the host name and port using PSQL commands
更新:
还可以通过将前缀import { Component } from '@angular/core';
import('../webcomponents/item.js').then(mm => {}); // works
const path = '../webcomponents/item.js';
import(path).then(mm => {}); // doesn't
@Component({
selector: 'app-root',
template: ``,
styles: [],
})
export class AppComponent {}
更改为jdbc:postgresql://localhost/mydb
和jdbc:postgresql://localhost:5432/mydb
。