我正在尝试使用EntityManager进行aspectj,它给出错误
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration',
Add a provider like Hibernate Validator (RI) to your classpath.
POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.12</version>
<scope>runtime</scope>
<!-- <version>1.8.0</version> -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<!-- <version>1.8.0</version> -->
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aspects</artifactId>
<version>0.22.5</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>ajc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
驱动程序应用程序:
@SpringBootApplication
@ComponentScan(basePackages = "aspect.*")
@EnableAspectJAutoProxy
@Configuration
@EntityScan(basePackages ="aspect.*")
public class Application{
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Application.class, args);
try {
Service service=context.getBean(Service.class);
service.save();
} catch (RuntimeException e) {
System.out.println("Caught runtime exception");
}
}
}
服务类:
@Component
public class Service{
@Autowired
EntityManager entityManager;
@Transactional
public void save() {
System.out.println("Before Invocation");
entityManager.persist(new Employee("009", "sunitha", "Lead"));
System.out.println("after persist call");
}
方面:
@Aspect
@Component
public class AuditAspect {
@Around("execution(* javax.persistence.EntityManager.persist(..)) && @annotation(loggable)")
public Object aroundServce(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable{
long start = System.currentTimeMillis();
// System.out.println("start--> "+start);
Object result = joinPoint.proceed();
Logger.info(this, "info %s just called", MethodSignature.class.cast(joinPoint.getSignature()).getMethod().getName());
return result;
}
}
application.properties:
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
需要知道哪里出错了?
答案 0 :(得分:0)
正如消息所说......它需要一个Bean Validation API(JSR 303)提供程序。如果你把一个像Hibernate-Validator或Apache BVAL这样的提供程序放在你的CLASSPATH中,我希望消息能够消失。