当你开始搞乱Spring的自动代理东西时,你经常遇到记录的这种行为:
实现BeanPostProcessor接口的类是特殊的,因此容器对它们的处理方式不同.所有BeanPostProcessors及其直接引用的bean将在启动时实例化,作为ApplicationContext的特殊启动阶段的一部分,然后所有这些BeanPostProcessors将以排序方式注册 - 并应用于所有其他bean.由于AOP自动代理是作为BeanPostProcessor本身实现的,因此没有BeanPostProcessors或直接引用的bean可以进行自动代理(因此不会将方面'编织'到它们中.
对于任何此类bean,您应该看到一条信息日志消息:"Bean'foo'不适合所有BeanPostProcessors处理(例如:不符合自动代理条件)".
换句话说,如果我编写自己的BeanPostProcessor,并且该类直接引用上下文中的其他bean,那么这些引用的bean将不符合自动代理的条件,并且会记录一条消息.
我的问题是跟踪直接引用的位置可能非常困难,因为"直接引用"实际上可以是一系列传递依赖,最终占用应用程序上下文中的一半bean.Spring提供的只是单个信息消息,并且除了告诉您何时在这个引用网中捕获了bean之外,它并没有太多帮助.
我正在开发的BeanPostProcessor确实有对其他bean的直接引用,但它是一组非常有限的引用.尽管如此,根据日志消息,我的上下文中的几乎每个bean都被排除在自动代理之外,但我无法看到依赖性发生在哪里.
有没有人找到更好的方法来跟踪这个?
我在Maven中设置Spring + Spring Data JPA + QueryDSL + JPA 2.0 + Hibernate时遇到了很多麻烦.我已经解决了很多问题,但是这个问题让我很头疼= /.
我收到以下异常:
Bean 'dataSource' of type [class org.springframework.jdbc.datasource.DriverManagerDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Run Code Online (Sandbox Code Playgroud)
我在谷歌看了一下,大多数时候这个问题是由缺少注释"@Transactional"引起的.我试图注释我的方法,但它没有解决任何问题.我绝对不知道它来自哪里=(.
这是我测试的代码:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="/applicationContext.xml")
public class BaseTest {
public BaseTest() {
}
@Before
public void setUp() throws IOException {
Dataset.loadDatabase();
}
@Test
public void load(){}
}
Run Code Online (Sandbox Code Playgroud)
DataSet类只是在db中做一些保存,看看它是否正常工作.
我的ApplicationContext.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<context:annotation-config/>
<jpa:repositories base-package="com.ae.repository" …Run Code Online (Sandbox Code Playgroud)