简体   繁体   中英

How to work with @SpringBootApplication and @Configuration, Datasource

I'm trying to work with a Firebird database and rest capabilities on Spring Boot, but getting: "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured."

I got an example and made a Spring Appication that connects to a Firebird database. This step is done and working. Now, I'm trying to add dependencies to provide rest resources. So, when I run the app, I'm expecting to retrieve data from Firebird and show it on browser as json.

@SpringBootApplication
@EntityScan("br.com.entity")
@EnableJpaRepositories("br.com.repository")
@ComponentScan("br.com.controller")
public class Application extends SpringBootServletInitializer {
 public static void main(String[] args) {
   AnnotationConfigApplicationContext context = new 
   AnnotationConfigApplicationContext(DataConfiguration.class);
   SpringApplication.run(Application.class, args);
  }
}

I´m expecting to retrive data from Firebird and show it on browser as json but it appears to be trying to configure 2 databases. The Firebird database connects but when it run SpringApplication.run(Application.class, args); it starts a new connection that I really dont need and crash.

Thanks Rawb.

I did that and it is working like a charm. This is the main application:

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}

And this is the config at application.properties

## default connection pool
spring.datasource.driver-class-name=org.firebirdsql.jdbc.FBDriver
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5

## FB
spring.datasource.url=jdbc:firebirdsql://myip:3050//mydb.FDB
spring.datasource.username=
spring.datasource.password=

spring.jpa.hibernate.ddl-auto=validate
spring.jpa.hibernate.dialect=org.hibernate.dialect.FirebirdDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM