คำถามติดแท็ก autowired

การเดินสายอัตโนมัติเป็นคุณลักษณะคอนเทนเนอร์ DI ที่การอ้างอิงจะถูกค้นหาโดยอัตโนมัติตามเกณฑ์บางอย่าง

17
@Autowired - ไม่พบถั่วที่มีคุณสมบัติสำหรับการพึ่งพา
ฉันเริ่มโครงการโดยสร้างเอนทิตีบริการและการทดสอบ JUnit สำหรับบริการโดยใช้ Spring และ Hibernate ทั้งหมดนี้ใช้งานได้ดี จากนั้นฉันได้เพิ่ม spring-mvc เพื่อสร้างเว็บแอปพลิเคชันนี้โดยใช้แบบฝึกหัดทีละขั้นตอน แต่เมื่อฉันพยายามสร้าง Controller ด้วยคำอธิบายประกอบ @Autowired ฉันได้รับข้อผิดพลาดจาก Glassfish ในระหว่างการปรับใช้ ฉันเดาว่าด้วยเหตุผลบางอย่าง Spring ไม่เห็นบริการของฉัน แต่หลังจากพยายามหลายครั้งฉันก็ยังไม่สามารถจัดการได้ ทดสอบบริการด้วย @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:/beans.xml"}) และ @Autowired MailManager mailManager; ทำงานได้อย่างถูกต้อง ตัวควบคุมที่ไม่มี @Autowired ด้วยฉันสามารถเปิดโครงการของฉันในเว็บเบราว์เซอร์ได้โดยไม่มีปัญหา /src/main/resources/beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd …
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.