67,513
社区成员
发帖
与我相关
我的任务
分享
:: Spring Boot :: (v1.5.2.RELEASE)
2017-04-17 20:35:07.575 INFO 5464 --- [ main] com.example.Application : Starting Application on th-PC with PID 5464 (D:\th\springboot\demo\target\classes started by th in D:\th\springboot\demo)
2017-04-17 20:35:07.884 INFO 5464 --- [ main] com.example.Application : No active profile set, falling back to default profiles: default
2017-04-17 20:35:08.640 INFO 5464 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7cb502c: startup date [Mon Apr 17 20:35:08 CST 2017]; root of context hierarchy
2017-04-17 20:35:11.046 INFO 5464 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$17bab5b6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-04-17 20:35:11.944 INFO 5464 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-04-17 20:35:12.008 INFO 5464 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-04-17 20:35:12.016 INFO 5464 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.11
2017-04-17 20:35:12.349 INFO 5464 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-04-17 20:35:12.350 INFO 5464 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3717 ms
2017-04-17 20:35:12.848 INFO 5464 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-04-17 20:35:12.860 INFO 5464 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-04-17 20:35:12.861 INFO 5464 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-04-17 20:35:12.862 INFO 5464 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-04-17 20:35:12.862 INFO 5464 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-04-17 20:35:13.024 WARN 5464 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userJpaDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.dao.UserJpaDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2017-04-17 20:35:13.034 INFO 5464 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2017-04-17 20:35:13.100 INFO 5464 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-04-17 20:35:13.497 ERROR 5464 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userJpaDao in com.example.base.service.UserServiceImpl required a bean of type 'com.example.dao.UserJpaDao' that could not be found.
Action:
Consider defining a bean of type 'com.example.dao.UserJpaDao' in your configuration.
package com.example.dao;
import org.springframework.stereotype.Component;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import com.example.User;
@Component
public interface UserJpaDao extends JpaRepository<User,Long>{
/**
* Find by name.
*
* @param name the name
* @return the user
*/
User findByName(String name);
/**
* Find user.
* User为@Entity 的名字
* @param name the name
* @return the user
*/
@Query("from UserInfo u where u.name=:name")
User findUser(@Param("name") String name);
}
package com.example.base.service;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.User;
import com.example.dao.UserJpaDao;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserJpaDao userJpaDao;
@Override
public User getUserByName(String username) {
// TODO Auto-generated method stub
return userJpaDao.findByName(username);
}
}
package com.example.base.service;
import com.example.User;
public interface UserService {
/**
* Gets the user by name.
*
* @param username the user name
* @return the user by name
*/
public User getUserByName(String username);
}
package com.example;
import org.springframework.boot.orm.jpa.*;
import org.springframework.boot.orm.jpa.hibernate.*;
import javax.persistence.*;
@Entity
@Table(name="userinfo")
public class User {
@Id
@GeneratedValue
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "password")
private String password;
@Column(name = "email")
private String email;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args)
{
SpringApplication.run(Application.class);
}
}
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args)
{
SpringApplication.run(Application.class);
}
}
加了,@SpringBootApplication,还是一样,同样的报错,而且我查过了@SpringBootApplication等效于@Configuration
@ComponentScan
@EnableAutoConfiguration
所以应该不是这个问题