मैं वसंत बूट डाटा जेपीए उपयोग कर रहा हूँ और अभी, मैं इस है:मैं स्प्रिंग में डेटास्रोत में जेपीए गुण कैसे लोड कर सकता हूं?
@Configuration
@PropertySource("classpath:persistence.properties")
@EnableTransactionManagement
public class PersistenceConfiguration {
@Autowired
private Environment env;
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
entityManager.setDataSource(this.dataSource());
entityManager.setPackagesToScan(new String[] {"com.example.movies.domain"});
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
entityManager.setJpaVendorAdapter(vendorAdapter);
entityManager.setJpaProperties(this.properties());
return entityManager;
}
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
private Properties properties() {
Properties properties = new Properties();
properties.setProperty("hibernate.ddl-auto", this.env.getProperty("spring.jpa.hibernate.ddl-auto"));
properties.setProperty("hibernate.dialect", this.env.getProperty("spring.jpa.hibernate.dialect"));
properties.setProperty("hibernate.show_sql", this.env.getProperty("spring.jpa.show-sql"));
return properties;
}
}
और मेरे persistence.properties
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/sarasa_db
spring.datasource.username=root
spring.datasource.password=myPassword
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=false
क्या मुझे पता करने के लिए होगा अगर वहाँ इन लोड करने के लिए किसी भी तरह से मौजूद है JpaProperties स्वचालित रूप से। मैं चाहता हूं कि वसंत इसे निर्मित करे क्योंकि अभी, अगर मैं persistence.properties में नई जेपीए संपत्ति जोड़ता हूं, तो यह तब तक नहीं देखा जाएगा जब तक कि मैं प्रॉपर्टी ऑब्जेक्ट में उस संपत्ति को तब तक नहीं डालता। तो, क्या आप जानते हैं कि यह संभव है? सादर!
ढांचे के चारों ओर ढांचे के साथ काम करें। असल में आप अपनी सभी कॉन्फ़िगरेशन को हटा सकते हैं क्योंकि स्प्रिंग बूट स्वचालित रूप से आपके लिए यह सब कॉन्फ़िगर करेगा। असल में जो आप डिफ़ॉल्ट रूप से काम करना चाहते हैं, लेकिन क्योंकि आपने उन सभी के आसपास काम किया है जो अब काम नहीं करते हैं। –
हां, अगर मैं सेवा से बूट करता हूं तो काम करता है। समस्या यह है कि मैं ऐसा नहीं करता जब मैं डोमेन लेयर में अपने परीक्षण चलाता हूं ... यही कारण है कि इसे मैन्युअल रूप से बना रहा है – jscherman
ऐसा न करें, आपको उसी तंत्र का उपयोग करना चाहिए और इसके आसपास काम नहीं करना चाहिए। –