org.springframework.beans.factory.beancreationexception: не удалось
Autowire Field: Private DAO.ProductDao
Controllers.homeController.ProductDao; Вложенное исключение -
org.springframework.beans.factory.nosuchbeandefinitionexception: no
квалификационная боба типа {@org.springframework.beans.factory.annotation.autowired (обязательный = true)} < /p>
< /blockquote>
исходный код: < /strong> < /p>
controller < /strong> < /p>
< /plorn> < /p>
< /plorn> < /p>
< /plorn> < /p>
controller < /strong>package controllers;
import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import dao.ProductDao;
import model.Product;
@Controller
public class HomeController {
@Autowired
private ProductDao productDao;
@RequestMapping("/")
public String home(){
return "home";
}
@RequestMapping("/productList")
public String getProducts(Model model) {
List
products = productDao.getAllProducts();
model.addAttribute("products", products);
return "productList";
}
@RequestMapping("/productList/viewProduct/{productId}")
public String viewProduct(@PathVariable String productId, Model model) throws IOException{
Product product = productDao.getProductById(productId);
model.addAttribute(product);
return "viewProduct";
}
< /code>
} < /p>
productdao < /strong> < /p>
package dao;
import java.util.List;
import org.springframework.stereotype.Component;
import model.Product;
public interface ProductDao {
void addProduct(Product product);
Product getProductById(String id);
List getAllProducts();
void deleteProduct(String id);
}
< /code>
productdaoimpl < /strong> < /p>
package dao.impl;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import dao.ProductDao;
import model.Product;
@Repository
@Transactional
public class ProductDaoImpl implements ProductDao {
@Autowired
private SessionFactory sessionFactory;
public void addProduct(Product product) {
Session session = sessionFactory.getCurrentSession();
session.saveOrUpdate(product);
session.flush();
}
public Product getProductById(String id) {
Session session = sessionFactory.getCurrentSession();
Product product = (Product) session.get(Product.class, id);
session.flush();
return product;
}
public List getAllProducts() {
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery("from Product");
List products = query.list();
session.flush();
return products;
}
public void deleteProduct(String id) {
Session session = sessionFactory.getCurrentSession();
session.delete(getProductById(id));
session.flush();
}
}
< /code>
entity (продукт) < /strong> < /p>
package model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String productId;
private String productName;
private String productCategory;
private String productDescription;
private double productPrice;
private String productCondition;
private String productStatus;
private int unitInStock;
private String productManufacture;
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductCategory() {
return productCategory;
}
public void setProductCategory(String productCategory) {
this.productCategory = productCategory;
}
public String getProductDescription() {
return productDescription;
}
public void setProductDescription(String productDescription) {
this.productDescription = productDescription;
}
public double getProductPrice() {
return productPrice;
}
public void setProductPrice(double productPrice) {
this.productPrice = productPrice;
}
public String getProductCondition() {
return productCondition;
}
public void setProductCondition(String productCondition) {
this.productCondition = productCondition;
}
public String getProductStatus() {
return productStatus;
}
public void setProductStatus(String productStatus) {
this.productStatus = productStatus;
}
public int getUnitInStock() {
return unitInStock;
}
public void setUnitInStock(int unitInStock) {
this.unitInStock = unitInStock;
}
public String getProductManufacture() {
return productManufacture;
}
public void setProductManufacture(String productManufacture) {
this.productManufacture = productManufacture;
}
}
< /code>
jdbc.properties
jdbc.username = ****
jdbc.password = ****
jdbc.driver = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/myeshop
< /code>
applicationcontext.xml
org.hibernate.dialect.MySQL5Dialect
dao
< /code>
dispatcher-servlet.xml
< /code>
web.xml
dispatcher
org.springframework.web.servlet.DispatcherServlet
1
dispatcher
/
eShop Database
DB Connection
jdbc/myeshop
javax.sql.DataSource
Container
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
WEB-INF/dispatcher-servlet.xml
WEB-INF/applicationContext.xml
< /code>
pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.mywebsite
emusicstore
0.0.1-SNAPSHOT
war
org.springframework
spring-webmvc
4.1.4.RELEASE
org.springframework
spring-core
4.1.1.RELEASE
org.springframework
spring-orm
4.1.4.RELEASE
org.hibernate
hibernate-core
4.0.1.Final
org.hibernate.javax.persistence
hibernate-jpa-2.0-api
1.0.1.Final
mysql
mysql-connector-java
6.0.5
jstl
jstl
1.2
taglibs
standard
1.1.2
org.apache.maven.plugins
maven-compiler-plugin
3.5.1
1.8
1.8
< /code>
Заранее спасибо!

Подробнее здесь: https://stackoverflow.com/questions/428 ... ringframew