- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我通过 spring ioc 编写了一些 Rest 应用程序。但我无法解决这个问题。这是我的异常(exception):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'angularController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.akifev.dao.ContactDao com.akifev.controllers.AngularController.contactDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.akifev.dao.ContactDao] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at com.akifev.controllers.AngularRun.main(AngularRun.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.akifev.dao.ContactDao com.akifev.controllers.AngularController.contactDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.akifev.dao.ContactDao] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 22 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.akifev.dao.ContactDao] 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)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 24 common frames omitted
我的applicationContext.xml(我所有的dao类都在“com.akifev.dao”中):
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:tx="http://www.springframework.org/schema/cache" xmlns:mvc="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<>
dbname="${mongo.dbname}"
mongo-ref="mongo"
/>
我的 DAO 之一:
@Repository
public class ContactDao {
@Autowired
MongoOperations mongoOperations;
public void save(Contact contact) {
mongoOperations.save(contact);
}
public Contact get(Long id) {
return mongoOperations.findOne(Query.query(Criteria.where("id").is(id)), Contact.class);
}
public List getAll() {
return mongoOperations.findAll(Contact.class);
}
public void remove(Long id) {
mongoOperations.remove(Query.query(Criteria.where("id").is(id)), Contact.class);
}
}
我的休息 Controller :
@Bộ điều khiển nghỉ ngơi
public class AngularController {
@Autowired
ContactDao contactDao;
@RequestMapping("/hola")
public String angularController(@RequestParam(value = "user", defaultValue = "user") String name){
//code for add the entry to database
return "added";
}
}
我尝试用@Qualifer对其进行注释,但没有使用。有人可以帮助我吗?感谢您的关注。
1 Câu trả lời
问题已解决。
解决我问题的注释是@ImportResources
.
关于java - 无法 Autowiring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28929650/
Đây là câu hỏi về phương pháp thực hành tốt nhất. Tôi đã nghe nhiều lần rằng: a) Khi Autowiring trong Spring, cách tốt nhất là Autowiring giao diện "chứ không phải" Autowiring phần triển khai. và.. b) Tôi cũng
Tôi đang xem lại một số ví dụ cũ trong không gian làm việc của mình. Tôi không thấy Autowiring được thực hiện như thế nào vì không có @Autowired. Cấu hình mặc định của Spring Boot + Facebook. @Bộ điều khiển @Yêu cầu
Có vẻ như không phải vậy. Tôi từng nghĩ rằng cấu hình XML có mục đích ghi đè chú thích. Nhưng khi tôi đặt autowire="no" trong cấu hình XML, các thuộc tính chú thích @Autowired của bean vẫn hoạt động. Tôi không còn chắc chắn về XML autowire nữa
Tại sao chúng ta cần Autowiring? Giải thích về khái niệm Autowiring là gì? Chú thích @autowired từ Spring Framework. Câu trả lời tốt nhất không yêu cầu Autowiring, nó chỉ là một sự tiện lợi.
Từ tài liệu Spring này, tôi biết rằng khi tôi sử dụng @Bean, giá trị mặc định đã tương đương với: @Bean(autowire = Autowire.NO) (Mặc định) Không có autowire
Tôi gặp phải một yêu cầu lạ. Tôi cần thêm một ID lỗi duy nhất vào thông báo log4j và trả về ID thông báo đó cho giao diện. Vì vậy, tôi nghĩ chúng ta hãy tạo một dịch vụ mùa xuân như thế này public cl
Câu hỏi này đã có câu trả lời: @Autowire không hoạt động với @Repository (3 câu trả lời) Đã đóng 4 năm trước. Tôi có một lớp "ReportEverythingForm" từ chối vượt qua tự động
Tôi mới đến mùa xuân. Tôi đang gặp sự cố với Spring-Boot. Tôi đang cố gắng tự động kết nối một trường từ tệp cấu hình bên ngoài vào một bean tự động kết nối. Tôi có lớp sau
Tôi có một ứng dụng Spring Boot với các kho lưu trữ. Tôi cũng đang sử dụng @Service và mở rộng kho lưu trữ bên trong nó. Khi tôi thử @Autowired một dịch vụ, tôi gặp phải: Nguyên nhân do: org.springfr
Tôi có giao diện C và muốn truy cập getClassName() trong hai lớp khác. Ngoại lệ trong method1() khi truy cập a.getClassName(). giao diện công cộng
Tôi đang gặp phải một vấn đề kỳ lạ khi một Thành phần được đưa vào @Autowired có sẵn trong một lớp nhưng lại không có trong lớp khác. Tôi sử dụng thuộc tính mạng trong các lớp Tài khoản và Thỏa thuận
Hãy xem xét mã ví dụ sau: public class SmallCar { private CarEngine carEngine; @Autowired public SmallCar
Sự khác biệt giữa autowire = "no" và autowire = "default" là gì? Nếu chúng giống nhau thì tại sao chúng ta lại có 2 lựa chọn này? Câu trả lời tốt nhất là Beans. Mặc định là "default
Tôi đã thay đổi dự án để sử dụng chú thích thay vì tệp xml nhưng điều này làm tăng thời gian triển khai ứng dụng. Bây giờ tôi đang tìm cách để giảm thiểu nó. Có sự khác biệt về hiệu suất giữa Autowiring theo loại và Autowiring theo tên không? Chào mừng nồng nhiệt bất kỳ
Tôi có một ứng dụng spring boot mà tôi sử dụng với plugin web. Trong một lớp tôi có: package com.test.company @Component @RestController pub
Tôi có một hệ thống thực hiện một số việc. Hệ thống tạo một luồng riêng cho từng đối tượng bằng phương pháp sau: stp.scheduleWithFixedDelay((EditSite) ctx.getBean("EditSite
Tôi đang cố gắng tự động kết nối kho lưu trữ nhưng không được. Tôi đã vật lộn với vấn đề này trong một tuần nay và có vẻ như tôi không thể tìm ra cách giải quyết. Điều thú vị là khi tôi bình luận về Autowiring cho kho lưu trữ nhân viên, chương trình hoạt động và biên dịch chính xác, nhưng ngay khi tôi thử Aut
Nghĩa là nếu không có nhiều hơn 1 bean có kiểu dữ liệu yêu cầu thì tất cả các trường của bean sẽ tự động được đưa vào phần phụ thuộc. Câu hỏi đặt ra là nó hoạt động như thế nào khi sử dụng chú thích và liệu nó có hoạt động hay không. Các thử nghiệm của tôi cho thấy rằng ngay cả khi tôi sử dụng @Resource
Tôi có một thành phần Tự động kết nối các bean khác: @Component public class MyComponent { @Autowired private Enviro
Đây là mã lớp của tôi, trong đó tôi có các trường @Autowired: Kiểm tra A @ContextConfiguration("classpath:spring.xml") public abstract class T
Tôi là một lập trình viên xuất sắc, rất giỏi!