目前,我正在使用@SpringBootApplication具有以下属性的默认注释application.properties:
spring.datasource.url=jdbc:mysql://localhost/dbname
spring.datasource.username=X
spring.datasource.password=X
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.naming_strategy=my.package.CustomNamingStrategy
Run Code Online (Sandbox Code Playgroud)
从JPA 2.1开始,我应该可以使用这些javax.persistence.schema-generation.*属性,但是在我的application.properties中设置它们似乎没有任何效果.
我见过的例子是这样那丝了一大堆额外的豆子,但他们没有使用MySQL.无论如何,这样做需要我配置春天为我提供的许多选项.
我的目标是:
我不想:
Lib版本:
hibernate : 4.3.11.FINAL
spring framework : 4.2.5.RELEASE
spring-boot : 1.3.3.RELEASE
spring-data-jpa : 1.10.1.RELEASE // for querydsl 4 support
spring-data-commons: 1.12.1.RELEASE // for querydsl 4 support
Run Code Online (Sandbox Code Playgroud)
(使用gradle,而不是maven)
我试图将Spring依赖注入到JPA EntityListener中.这是我的听众课程:
@Configurable(autowire = Autowire.BY_TYPE, dependencyCheck = true)
public class PliListener {
@Autowired
private EvenementPliRepository evenementPliRepository;
@PostPersist
void onPostPersist(Pli pli) {
EvenementPli ev = new EvenementPli();
ev.setPli(pli);
ev.setDateCreation(new Date());
ev.setType(TypeEvenement.creation);
ev.setMessage("Création d'un pli");
System.out.println("evenementPliRepository: " + evenementPliRepository);
evenementPliRepository.save(ev);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Entity类:
@RooJavaBean
@RooToString
@RooJpaActiveRecord
@EntityListeners(PliListener.class)
public class Pli implements Serializable{
...
Run Code Online (Sandbox Code Playgroud)
但是,我的依赖(即evenementPliRepository)始终为null.
有人可以帮忙吗?