NutzCN Logo
问答 @Inject 没有成功注入
发布于 2581天前 作者 wx_dc1uhcoqb670vfspa24d 2180 次浏览 复制 上一个帖子 下一个帖子
标签:
@IocBean
public class AliCdnService {
    private static final String cdn_server_address = "https://cdn.aliyuncs.com";
    @Inject
    private AliConfiguration aliConfiguration;//未注入
@IocBean
public class AliyunService{
    @Inject
    private AliConfiguration aliConfiguration;//成功注入
@IocBean
public class AliConfiguration {

    @Inject("java:$conf.get('ali.article.bucketName')")
    private String artBucketName;

统一包下的俩个服务,是什么原因造成的呢

9 回复

日志里面有提示AliCdnService的ioc定义从哪里加载

[DEBUG] 2017-11-28 11:04:10,477 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [POST] path=/platform/gf/tool/refresh/urls : GfToolController.refreshUrls(GfToolController.java:138)
[DEBUG] 2017-11-28 11:04:10,478 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'shiroUtil'<class cn.wizzer.framework.util.ShiroUtil>
[DEBUG] 2017-11-28 11:04:10,478 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'dateUtil'<class cn.wizzer.framework.util.DateUtil>
[DEBUG] 2017-11-28 11:04:10,478 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'stringUtil'<class cn.wizzer.framework.util.StringUtil>
[DEBUG] 2017-11-28 11:04:10,478 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'gfToolController'<class cn.wizzer.app.web.modules.controllers.platform.gf.GfToolController>
Exception in thread "pool-4-thread-3" java.lang.NullPointerException
[DEBUG] 2017-11-28 11:04:10,514 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [POST]URI=/platform/gf/tool/refresh/urls 34ms
	at cn.wizzer.app.web.commons.services.ali.AliCdnService.compose_url(AliCdnService.java:82)
	at cn.wizzer.app.web.commons.services.ali.AliCdnService.refreshObjectCaches(AliCdnService.java:51)
	at cn.wizzer.app.web.modules.controllers.platform.gf.GfToolController$1.run(GfToolController.java:144)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

没有注入的日志

[DEBUG] 2017-11-28 11:04:40,924 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [POST] path=/platform/gf/article/editDo : GfArticleController.editDo(GfArticleController.java:525)
[DEBUG] 2017-11-28 11:04:40,925 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'shiroUtil'<class cn.wizzer.framework.util.ShiroUtil>
[DEBUG] 2017-11-28 11:04:40,925 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'dateUtil'<class cn.wizzer.framework.util.DateUtil>
[DEBUG] 2017-11-28 11:04:40,925 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'stringUtil'<class cn.wizzer.framework.util.StringUtil>
[DEBUG] 2017-11-28 11:04:40,927 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'gfArticleController'<class cn.wizzer.app.web.modules.controllers.platform.gf.GfArticleController>
[DEBUG] 2017-11-28 11:04:40,928 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * FROM article  WHERE id=?
    |                   1 |
    |---------------------|
    | 6334238834569515008 |
  For example:> "SELECT * FROM article  WHERE id='6334238834569515008'"
class="articleImg" _src="http://img.guanfumuseum.org.cn/1510199964363.png"/
class="articleImg" _src="http://img.guanfumuseum.org.cn/1510200006708.png"/
class="articleImg" _src="http://img.guanfumuseum.org.cn/1510200073162.png"/
class="articleImg" _src="http://img.guanfumuseum.org.cn/1510200149965.png"/
[DEBUG] 2017-11-28 11:04:40,934 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * FROM user_profile  WHERE user_id=? LIMIT 0, 1 
    |                   1 |
    |---------------------|
    | 6273419132956315648 |
  For example:> "SELECT * FROM user_profile  WHERE user_id='6273419132956315648' LIMIT 0, 1 "
[DEBUG] 2017-11-28 11:04:40,954 org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:122) - CookieSpec selected: default
[DEBUG] 2017-11-28 11:04:40,955 org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:76) - Auth cache not set in the context
[DEBUG] 2017-11-28 11:04:40,955 org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:249) - Connection request: [route: {}->http://guanfu-article.oss-cn-beijing.aliyuncs.com:80][total kept alive: 0; route allocated: 0 of 1024; total allocated: 0 of 1024]
[DEBUG] 2017-11-28 11:04:40,956 org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:282) - Connection leased: [id: 1][route: {}->http://guanfu-article.oss-cn-beijing.aliyuncs.com:80][total kept alive: 0; route allocated: 1 of 1024; total allocated: 1 of 1024]
[DEBUG] 2017-11-28 11:04:40,956 org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:234) - Opening connection {}->http://guanfu-article.oss-cn-beijing.aliyuncs.com:80
[DEBUG] 2017-11-28 11:04:40,971 org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:138) - Connecting to guanfu-article.oss-cn-beijing.aliyuncs.com/59.110.185.190:80
[DEBUG] 2017-11-28 11:04:40,988 org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:145) - Connection established 10.0.0.111:60168<->59.110.185.190:80
[DEBUG] 2017-11-28 11:04:40,989 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.setSocketTimeout(LoggingManagedHttpClientConnection.java:90) - http-outgoing-1: set socket timeout to 50000
[DEBUG] 2017-11-28 11:04:40,989 org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:255) - Executing request PUT /6334238834569515008.html HTTP/1.1
[DEBUG] 2017-11-28 11:04:40,990 org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:266) - Proxy auth state: UNCHALLENGED
[DEBUG] 2017-11-28 11:04:40,990 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:135) - http-outgoing-1 >> PUT /6334238834569515008.html HTTP/1.1
[DEBUG] 2017-11-28 11:04:40,990 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:138) - http-outgoing-1 >> Authorization: OSS LTAIDAGAS4hUxGHB:IgXctkxZUiiLQl2jqkqHYm8Fdjg=
[DEBUG] 2017-11-28 11:04:40,991 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:138) - http-outgoing-1 >> Date: Tue, 28 Nov 2017 03:04:40 GMT
[DEBUG] 2017-11-28 11:04:40,991 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:138) - http-outgoing-1 >> Content-Type: text/html
[DEBUG] 2017-11-28 11:04:40,991 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:138) - http-outgoing-1 >> Transfer-Encoding: chunked
[DEBUG] 2017-11-28 11:04:40,992 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:138) - http-outgoing-1 >> Host: guanfu-article.oss-cn-beijing.aliyuncs.com
[DEBUG] 2017-11-28 11:04:40,992 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:138) - http-outgoing-1 >> Connection: Keep-Alive
[DEBUG] 2017-11-28 11:04:40,992 org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:138) - http-outgoing-1 >> User-Agent: aliyun-sdk-java/2.6.0(Mac OS X/10.13.1/x86_64;1.8.0_121)

成功注入的日志

是哪部分需要关注呢?我没看出来


[DEBUG] 2017-11-28 11:09:25,118 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:80) - Found @IocBean : class cn.wizzer.app.web.commons.config.AliConfiguration

启动日志中已经加载过啦

搜AliCdnService字样的日志,贴出来

贴全呗
看看AliCdnService有没有加载,它也要是被Ioc容器管理的才行
AliCdnService不会是你自己new的吧?


[DEBUG] 2017-11-28 11:09:25,265 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:80) - Found @IocBean : class cn.wizzer.app.web.commons.services.ali.AliCdnService

beans = ["aliCdnService"] beans中也有

[DEBUG] 2017-11-28 11:09:31,810 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:163) - Found IocObject(aliCdnService) in AnnotationIocLoader(packages=[cn.wizzer])


[DEBUG] 2017-11-28 11:09:56,339 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'aliCdnService'<class cn.wizzer.app.web.commons.services.ali.AliCdnService> [DEBUG] 2017-11-28 11:09:56,340 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:183) - >> Load definition name=aliCdnService [DEBUG] 2017-11-28 11:09:56,340 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:163) - Found IocObject(aliCdnService) in AnnotationIocLoader(packages=[cn.wizzer]) [DEBUG] 2017-11-28 11:09:56,340 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:215) - >> Make...'aliCdnService'<class cn.wizzer.app.web.commons.services.ali.AliCdnService> [DEBUG] 2017-11-28 11:09:56,340 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) - Save object 'aliCdnService' to [app]

[DEBUG] 2017-11-28 11:18:22,125 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:163) - Found IocObject(aliCdnService) in AnnotationIocLoader(packages=[cn.wizzer])

是通过
@IocBean注入的Service 不是自己new的

debug一下AliCdnService的构造方法,看看哪里调用过.

另外, 是不是没编译/install

添加回复
请先登陆
回到顶部