Announcement Announcement Module
Collapse
No announcement yet.
Custom Scope, JPanel and AOP scoped-bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Scope, JPanel and AOP scoped-bean

    I am trying to use a custom scope and it seems to work fine when simple POJO's are configured to use the scope, but if I use anything that is or derives from JPanel I suddenly get the following exception:
    Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at javax.swing.BufferStrategyPaintManager.flushAccumulatedRegion(BufferStrategyPaintManager.java:406)
    	at javax.swing.BufferStrategyPaintManager.endPaint(BufferStrategyPaintManager.java:370)
    	at javax.swing.RepaintManager.endPaint(RepaintManager.java:1192)
    	at javax.swing.JComponent.paint(JComponent.java:1016)
    	.....
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException
    	at javax.swing.LayoutComparator.compare(LayoutComparator.java:72)
    	at java.util.Arrays.mergeSort(Arrays.java:1270)
    	at java.util.Arrays.sort(Arrays.java:1210)
    	at java.util.Collections.sort(Collections.java:159)
    	....
    This is a swing-related error so I am wondering if there are issues with CGLIb and Swing but I can't find anything on the net about it.

    My applicationContext.xml looks like this:
    Code:
    	<bean id="mainWindow" class="MainWindow" init-method="init">
    		<property name="display"><ref bean="display1"/></property>
    	</bean>
    	
    	<bean id="display1" class="javax.swing.JPanel">
    		<aop:scoped-proxy />
    	</bean>
    And here is the code for MainWindow:
    Code:
    public class MainWindow extends JFrame {
    
    	private JPanel display;
    
    	public void init() {
    		setLayout(new BorderLayout());
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setSize(200, 200);
    		add(display, BorderLayout.CENTER);
    		setVisible(true);
    	}
    
    	public JPanel getDisplay() {
    		return display;
    	}
    
    	public void setDisplay(JPanel display) {
    		this.display = display;
    		display.setBackground(Color.red);
    	}
    }
    It's about as simple as it gets but it throws the exception.

    If I comment out "add(display, BorderLayout.CENTER)" code, the exception doesn't occur.

    If I remove <aop:scoped-proxy> from the applicationContext.xml, then the panel works as normal but obviously my custom scope will not work.

    I have tried <aop:scoped-proxy proxy-target-class="false"/> which still causes an exception, but a different one:
    Code:
    Caused by: java.lang.IllegalAccessError: class javax.swing.$Proxy0 cannot access its superinterface javax.swing.TransferHandler$HasGetTransferHandler
    	at java.lang.reflect.Proxy.defineClass0(Native Method)
    	at java.lang.reflect.Proxy.getProxyClass(Proxy.java:504)
    	at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(JdkDynamicAopProxy.java:117)
    	...
    I am not familiar with Spring AOP - I am just using it to get custom scopes to work. Am I doing something wrong?

    Thanks,
    Paul Drummond
Working...
X