简体   繁体   中英

Spring 3 bean is not being wired correctly

I have a web controller which I configure in the controller-config.xml using

<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.ecommerce.web.controller" />

The controller has the @Controller annotation like below.

@Controller
public class HomeController

I have included the @Autowired annotation on the dependencies, but when I first start up the application I am unable to set any properties on the wired objects.

For example, I have a storeProfile object which when in debug mode I see has multiple properties set as it should. But, when I try to set one of the storeProfile properties on an @Autowried bean it is still null or empty string!?

If you look at the attached images it shows that after I step past the line this.storeProfileContext.setStoreProfile(storeProf ile) the debugger still shows the storeProfile property as null

Actually, there are a couple dependencies which look like they are created (they are not null and the application functions), but I am unable to set anything on these objects.

I asked the same question on the Spring forums too - hoping to get this figured out.

Thanks so much!

调试器屏幕截图

Bean配置

这是因为您正在查看代理的字段,该字段是在具有<aop:scoped-proxy/> ,如果调用getter作为设置值,则应该看到从代理对象检索到的正确值。

The instances you are examining are CGLIB proxies.

CGLIB subclasses your beans, delegating all method invocations to the target beans.

So the fields of the super classes are still present but not used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM