9

I'm woundering if it's possible to disable the intialization of JPA Stack competelly.

I some situation my application is executed in enviroment where database is not accessible. Application can survive this on application level. But technically i get some exception on intialization of Data Source.

  1. there musst be some way to disable JPA intialization at all (not needed withoud db. By profile or someting like that.
  2. Or maby at least i can say Connection pool to not connect or somethinglike this.
  3. Other ideas?

1 Answer 1

9

Yes, you could use profiles for that: one with JPA and another without it. To turn off DataSource/JPA autoconfiguration you need to add spring.autoconfigure.excludes property (with fully-qualified class names) to profile-specific application.properties.

What classes to exclude? I suggest to start from DataSourceAutoConfiguration and if it's not enough try to disable other database-related autoconfiguration classes.

Note that spring.autoconfigure.excludes is a new feature that is avaiable since Spring Boot 1.3.0.M3

Sign up to request clarification or add additional context in comments.

9 Comments

Yes, but how to make that "eclusion" conditionaly to Profile. And Secondly: How then to deal with Autowired. Would mean in need custom factories? Maybe some exmaple helps me
Ok Autowirede can have Required=false... Now i hvae to figure out how to make EnableAutoConfiguration(exclude = DataSourceAutoConfiguration .class) conditional, depending on Profile
spring.autoconfigure.excludes is analogue of EnableAutoConfiguration(exclude = ) that may be used in application.properties. Just put it in application-nodb.properties file where nodb is a name of profile.
Here i try to exclude DataSourceAutoconfig, (So it not tries to establish connection) spring.autoconfigure.excludes=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration. But it's not working, no chnage to behavior. Tried with DataSourceAutoConfiguration too... Spring boot 1.3.0.M5
Run application with --debug: has it shown as enabled?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.