在启动期间运行spring boot应用程序时,我遇到异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.client.RestTemplate com.micro.test.controller.TestController.restTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.client.RestTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Run Code Online (Sandbox Code Playgroud)
我在TestController中自动装配RestTemplate.我正在使用Maven进行依赖管理.
TestMicroServiceApplication.java
package com.micro.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestMicroServiceApplication {
public static void main(String[] args) {
SpringApplication.run(TestMicroServiceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
TestController.java
package com.micro.test.controller; …
Run Code Online (Sandbox Code Playgroud) 我在gradle项目的intellij中遇到错误。我正在导入现有的gradle项目,并尝试在gradle窗口中刷新它。
Error:No such property: GradleVersion for class: JetGradlePlugin
Run Code Online (Sandbox Code Playgroud)
请指教。
Stream st = Stream.of(1,2,3,4);
Run Code Online (Sandbox Code Playgroud)
这是创建整数流(通过在运行时推断)还是对象流?
st.collect(Collectors.averagingInt((Integer x)->x));
Run Code Online (Sandbox Code Playgroud)
这条线很好.
st.forEach((Integer x)-> System.out.println(x));
Run Code Online (Sandbox Code Playgroud)
这行不编译.它在(整数x)处给出一个编译错误,说出预期的对象但是找到了Integer.为什么?
为什么上面的averagingInt方法没有抱怨相同?
averagingInt将ToIntFunction接口作为原始引用类型,<? super T>
并允许Integer值.虽然forEach正在使用与原始引用类型相同的Consumer接口,<? super T>
但编译器正在抱怨Integer参数值.