NutzCN Logo
问答 新建的Controller失效,无法注入,其他的都正常
发布于 188天前 作者 franktrue 315 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

新建了一个ApiController
报错如下

[DEBUG] 19:02:38.602 [qtp1954985045-16] org.nutz.ioc.impl.ScopeContext - Remove object 'apiController' from [app] 
[DEBUG] 19:02:38.602 [qtp1954985045-16] cn.wizzer.app.web.commons.processor.LogTimeProcessor - [POST]URI=/food/api/word/big_kind 14ms
[WARN ] 19:02:38.602 [qtp1954985045-16] cn.wizzer.app.web.commons.processor.WkFailProcessor - Error@/food/api/word/big_kind :
org.nutz.ioc.IocException: IocBean[apiController] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:49)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:22)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
	at cn.wizzer.app.web.commons.filter.RouteFilter.doFilter(RouteFilter.java:31)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
	at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:171)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1602)
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:214)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1701)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1668)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:502)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:132)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: IocBean[apiController] fail at field=[foodSmallKindService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 63 common frames omitted
Caused by: org.nutz.ioc.IocException: IocBean[class:cn.wizzer.app.food.modules.services.FoodSmallKindService] none ioc bean match class=cn.wizzer.app.food.modules.services.FoodSmallKindService
	at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:461)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 65 common frames omitted
9 回复

写的很清楚,FoodSmallKindService的问题

@wendal
我真不知道错在哪了……

package cn.wizzer.app.food.modules.services;

import cn.wizzer.app.food.modules.models.Food_small_kind;
import cn.wizzer.framework.base.service.BaseService;

public interface FoodSmallKindService extends BaseService<Food_small_kind> {
}

package cn.wizzer.app.food.modules.services.impl;

import cn.wizzer.app.food.modules.models.Food_small_kind;
import cn.wizzer.app.food.modules.services.FoodSmallKindService;
import cn.wizzer.framework.base.service.BaseServiceImpl;
import com.alibaba.dubbo.config.annotation.Service;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;

@IocBean(args = {"refer:dao"})
@Service(interfaceClass= FoodSmallKindService.class)
public class FoodSmallKindServiceImpl extends BaseServiceImpl<Food_small_kind> implements FoodSmallKindService {
    public FoodSmallKindServiceImpl(Dao dao) { super(dao); }
}

求大神指教。

注入FoodSmallKindService的地方,加@Reference

@wendal
都加了

package cn.wizzer.app.web.modules.controllers.platform.food;

import cn.wizzer.app.food.modules.models.*;
import cn.wizzer.app.food.modules.services.*;
import cn.wizzer.framework.base.Result;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

/**
 * 数据同步接口
 */
@IocBean
@At("/food/api")
public class ApiController {
    private static final Log log = Logs.get();

    @Inject
    @Reference
    private FoodDetectDataService foodDetectDataService;

    @Inject
    @Reference
    private FoodTestStandardService foodTestStandardService;

    @Inject
    @Reference
    private FoodBigKindService foodBigKindService;

    @Inject
    @Reference
    private FoodSmallKindService foodSmallKindService;

    @Inject
    @Reference
    private FoodWordService foodWordService;

    @Inject
    @Reference
    private FoodTestItemService foodTestItemService;

    /**
     * 添加检测数据
     * @param detectData
     * @return
     */
    @At("/detect/data")
    @Ok("json")
    @POST
    public Object addDetectData(@Param("..") Food_detect_data detectData) {
        //匹配检测标准
        Cnd cnd = Cnd.NEW();
        cnd.and("kindId", "=", detectData.getKindId())
                .and("testItemId", "=", detectData.getTestItemId());
        Food_test_standard testStandard = foodTestStandardService.fetch(cnd);
        if(testStandard!=null) {
            detectData.setTestStandardId(testStandard.getId());
        }else {
            log.info(detectData);
        }
        try {
            foodDetectDataService.insert(detectData);
            foodDetectDataService.clearCache();
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @At("/test")
    @Ok("json")
    public void test() {
        System.out.println("test");
    }

    /**
     * 同步食品大类
     * @param bigKind
     * @return
     */
    @At("/word/big_kind")
    @Ok("json")
    @POST
    public Object syncBigKind(@Param("..") Food_big_kind bigKind) {
        try {
            foodBigKindService.insertOrUpdate(bigKind);
            foodWordService.clearCache();
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    /**
     * 同步食品小类
     * @param smallKind
     * @return
     */
    @At("/word/big_kind")
    @Ok("json")
    @POST
    public Object syncSmallKind(@Param("..") Food_small_kind smallKind) {
        try {
            foodSmallKindService.insertOrUpdate(smallKind);
            foodWordService.clearCache();
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    /**
     * 同步检测项目
     * @param testItem
     * @return
     */
    @At("/test/item")
    @Ok("json")
    @POST
    public Object syncTestItem(@Param("..")Food_test_item testItem) {
        try {
            foodTestItemService.insertOrUpdate(testItem);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}

@wendal 我知道了……自动引入的锅……引用的Reference不对……,感谢

用了哪个Reference类?

@wendal
用的

import jdk.nashorn.internal.ir.annotations.Reference;

应该用

import com.alibaba.dubbo.config.annotation.Reference;

配一下import的排除模式, 就能避免了

@wendal
好的,非常感谢!

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