Consider defining a bean of type 'com.bird.ty.controller.GirlProperties' in your configuration.
启动报错
package com.bird.ty.controller;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "girl" )
@Component
public class GirlProperties {
private String size;
private Integer age;
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
@Controller
@EnableAutoConfiguration
public class HelloCtrl {
@Autowired
GirlProperties girlProperties;
@Value("${info}")
private String info;
@RequestMapping("/hello")
@ResponseBody
String home() {
return girlProperties.getSize();
}
public static void main(String[] args) throws Exception {
SpringApplication.run(HelloCtrl.class, args);
}
}
报了下面的错:
H:\programSetUp\jdk1.8.0_144\bin\java "-javaagent:H:\programSetUp\idea\IntelliJ IDEA 2017.3.1\lib\idea_rt.jar=50385:H:\programSetUp\idea\IntelliJ IDEA 2017.3.1\bin" -Dfile.encoding=UTF-8 -classpath H:\programSetUp\jdk1.8.0_144\jre\lib\charsets.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\deploy.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\access-bridge-64.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\cldrdata.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\dnsns.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\jaccess.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\jfxrt.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\localedata.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\nashorn.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\sunec.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\ext\zipfs.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\javaws.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\jce.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\jfr.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\jfxswt.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\jsse.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\management-agent.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\plugin.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\resources.jar;H:\programSetUp\jdk1.8.0_144\jre\lib\rt.jar;G:\projectModel\SpringBootModel\target\classes;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\boot\spring-boot-starter-web\1.5.9.RELEASE\spring-boot-starter-web-1.5.9.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\boot\spring-boot-starter\1.5.9.RELEASE\spring-boot-starter-1.5.9.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\boot\spring-boot\1.5.9.RELEASE\spring-boot-1.5.9.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\boot\spring-boot-autoconfigure\1.5.9.RELEASE\spring-boot-autoconfigure-1.5.9.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\boot\spring-boot-starter-logging\1.5.9.RELEASE\spring-boot-starter-logging-1.5.9.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\ch\qos\logback\logback-classic\1.1.11\logback-classic-1.1.11.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\ch\qos\logback\logback-core\1.1.11\logback-core-1.1.11.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\slf4j\jcl-over-slf4j\1.7.25\jcl-over-slf4j-1.7.25.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\slf4j\log4j-over-slf4j\1.7.25\log4j-over-slf4j-1.7.25.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\yaml\snakeyaml\1.17\snakeyaml-1.17.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\boot\spring-boot-starter-tomcat\1.5.9.RELEASE\spring-boot-starter-tomcat-1.5.9.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\apache\tomcat\embed\tomcat-embed-core\8.5.23\tomcat-embed-core-8.5.23.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\apache\tomcat\tomcat-annotations-api\8.5.23\tomcat-annotations-api-8.5.23.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\apache\tomcat\embed\tomcat-embed-el\8.5.23\tomcat-embed-el-8.5.23.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.23\tomcat-embed-websocket-8.5.23.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\hibernate\hibernate-validator\5.3.6.Final\hibernate-validator-5.3.6.Final.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\jboss\logging\jboss-logging\3.3.1.Final\jboss-logging-3.3.1.Final.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\com\fasterxml\jackson\core\jackson-databind\2.8.10\jackson-databind-2.8.10.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\com\fasterxml\jackson\core\jackson-annotations\2.8.0\jackson-annotations-2.8.0.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\com\fasterxml\jackson\core\jackson-core\2.8.10\jackson-core-2.8.10.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\spring-web\4.3.13.RELEASE\spring-web-4.3.13.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\spring-aop\4.3.13.RELEASE\spring-aop-4.3.13.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\spring-beans\4.3.13.RELEASE\spring-beans-4.3.13.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\spring-context\4.3.13.RELEASE\spring-context-4.3.13.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\spring-webmvc\4.3.13.RELEASE\spring-webmvc-4.3.13.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\spring-expression\4.3.13.RELEASE\spring-expression-4.3.13.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\spring-core\4.3.13.RELEASE\spring-core-4.3.13.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\org\springframework\boot\spring-boot-configuration-processor\1.5.9.RELEASE\spring-boot-configuration-processor-1.5.9.RELEASE.jar;H:\programPacket\apache-maven-3.5.0-bin\localRep\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar com.bird.ty.controller.HelloCtrl
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.9.RELEASE)
2017-12-28 13:10:11.295 INFO 7536 --- [ main] com.bird.ty.controller.HelloCtrl : Starting HelloCtrl on teddy-HP with PID 7536 (G:\projectModel\SpringBootModel\target\classes started by teddy in G:\projectModel\SpringBootModel)
2017-12-28 13:10:11.297 INFO 7536 --- [ main] com.bird.ty.controller.HelloCtrl : No active profile set, falling back to default profiles: default
2017-12-28 13:10:11.322 INFO 7536 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@184cf7cf: startup date [Thu Dec 28 13:10:11 CST 2017]; root of context hierarchy
2017-12-28 13:10:12.249 INFO 7536 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8082 (http)
2017-12-28 13:10:12.249 INFO 7536 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-12-28 13:10:12.249 INFO 7536 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
2017-12-28 13:10:12.327 INFO 7536 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-12-28 13:10:12.327 INFO 7536 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1005 ms
2017-12-28 13:10:12.423 INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-12-28 13:10:12.423 INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-12-28 13:10:12.423 INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-12-28 13:10:12.423 INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-12-28 13:10:12.423 INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-12-28 13:10:12.454 WARN 7536 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helloCtrl': Unsatisfied dependency expressed through field 'girlProperties'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.bird.ty.controller.GirlProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2017-12-28 13:10:12.454 INFO 7536 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-12-28 13:10:12.469 INFO 7536 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-12-28 13:10:12.547 ERROR 7536 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field girlProperties in com.bird.ty.controller.HelloCtrl required a bean of type 'com.bird.ty.controller.GirlProperties' that could not be found.
Action:
Consider defining a bean of type 'com.bird.ty.controller.GirlProperties' in your configuration.
Process finished with exit code 1
有谁知道为什么吗????