Could not autowire. No beans of 'int' type found. less... (Ctrl+F1) Checks autowiring probl
Posted xiufengchen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Could not autowire. No beans of 'int' type found. less... (Ctrl+F1) Checks autowiring probl相关的知识,希望对你有一定的参考价值。
package com.cxy.netty.controller; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioserverSocketChannel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import java.net.InetSocketAddress; @Component public class NettyServer { private int port; public int getPort() { return port; } public void setPort(int port) { this.port = port; } public NettyServer(int port) { this.port = port; } public void start() throws Exception { System.out.println("启动记载netty"); EventLoopGroup boss = new NioEventLoopGroup(); EventLoopGroup work = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); b.group(boss,work) .channel(NioServerSocketChannel.class) .localAddress(new InetSocketAddress(port)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new EchoServerHandler()); } }); System.out.println("启动加载netty2"); ChannelFuture channelFuturef = b.bind().sync(); if (channelFuturef.isSuccess()){ System.out.println("启动成功"); } } }
可以看到这个地方报错,笔者以为是idea的问题,所以强行启动,也还是报错,
仔细阅读了下,错误:
Could not autowire. No beans of ‘int‘ type found. less... (Ctrl+F1) Checks autowiring problems in a bean class.
这个bean无法被注入,代表这个bean是被spring管理的,然后post无法找到,
这个bean初始化的时候需要传入参数,所有spring是无法找到这个参数,所以报了这个错,
那么解决方法:首先,看你这个bean是否想被spring管理,如果不想,那么就就行将注解除去就好如果想被管理,那么就可以额加上,然后添加这个值
以上是关于Could not autowire. No beans of 'int' type found. less... (Ctrl+F1) Checks autowiring probl的主要内容,如果未能解决你的问题,请参考以下文章
Java--使用@Autowired报错Could not autowire. No beans of ‘XX‘ type found.
分享知识-快乐自己:intellij Idea报错Could not autowire. No beans of...
Spring Batch 解决 Could not autowire. No beans of ‘StepBuilderFactory‘ type found.
Could not autowire. No beans of ‘xxx” type found(三种方法)
Could not autowire. No beans of 'TbItemMapper' type found. less... (Ctrl+F1) Checks autowir