I'm trying to test my Spring DAO level but cannot connect to my local database. Here is the Configuration.
Yes, I use port 54321 instead of standard port 5432:
@Bean
public DataSource dataSource(){
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setPassword("password");
dataSource.setUsername("postgres");
dataSource.setUrl("jdbc:postgresql://localhost:53421/mydbtest");
dataSource.setDriverClassName("org.postgresql.Driver");
return dataSource;
}
@Bean
public JdbcTemplate jdbcTemplate(){
JdbcTemplate template = new JdbcTemplate();
template.setDataSource(dataSource());
return template;
}
@Bean
public DataSourceInitializer dataSourceInitializer(DataSource dataSource)
{
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
dataSourceInitializer.setDataSource(dataSource);
dataSourceInitializer.setEnabled(true);
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator.addScript(new ClassPathResource("src/resource/sql/01_init_database.sql"));
dataSourceInitializer.setDatabasePopulator(databasePopulator);
return dataSourceInitializer;
}
I switched the firewall off, tried different versions of postgresql driver. But I stilll get this exception. And he also writes me to check my user-password-port data, but I'm sure they are correct:
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
What could be also wrong?
I use postgresql 9.2
UPDATE
I am on Windows if it matters
Here is the line for pg_hba.conf
host all all 0.0.0.0/0 trust
(I also tried md5)
Here a Snippet form postgres.conf
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 54321 # (change requires restart)
max_connections = 100 # (change requires restart)
psqlor another SQL client? Doeslocalhostactually resolve to an IP address? (doesping localhostwork?) What is the value oflisten_addressinpostgresql.conf