我在sts中创建了一个maven项目,并试图为该项目创建一个war文件。我还为我的类配置了querydsl。当我运行maven install时,一个类给我一个错误响应。
错误:创建在文件[C:\ Users \ Vince \ Documents \ workspace-spring-tool-suite-4-4 . 0 . 1 . release \ project \ target \ test-classes \ com \ project \ project \ store based \ productBrandController . class]中定义的名为“productBrandController”的bean时出错:通过构造函数参数0表示的不满足的依赖关系;嵌套异常为org . spring framework . beans . factory . beancreationexception:创建名为“productBrandRepository”的bean时出错:调用init方法失败;嵌套异常为org . spring framework . beans . bean instantiation exception:无法实例化[org . spring framework . data . MongoDB . repository . support . querydslmongopredicteexecutor]:构造函数引发异常;嵌套异常为Java . lang . illegalargumentexception:未找到查询类项目。域类项目的QProductBrand。StoreBased.ProductBrand!
我需要有关我的pom文件的帮助(不确定javax.xml.bind是否可能是罪魁祸首),我也不确定我的输出目录是否正确(我已经尝试了java而不是注释作为输出)。非常感谢您的帮助!
这是课堂
import java.util.ArrayList;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.IndexDirection;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "ProductBrand")
public class ProductBrand {
@Id
private String id;
private ProductsBasic basic;
@Indexed(direction = IndexDirection.ASCENDING)
private String name;
@Indexed(direction = IndexDirection.ASCENDING)
private String units;
@Indexed(direction = IndexDirection.ASCENDING)
private double price;
@Indexed(direction = IndexDirection.ASCENDING)
private double price100g;
private String manufacturer;
private List<Manufacturer> manufacturerIndex;
private boolean organic;
private List<Organic> organicIndex;
private String category;
private List<Category> categoryIndex;
private String subCategory;
private List<SubCategory> subCategoryIndex;
private boolean seasonal;
private List<Seasonal> seasonalIndex;
private boolean frozenGoods;
private List<FrozenGoods> frozenGoodsIndex;
private boolean refrigeratedGoods;
private List<RefrigeratedGoods> refrigeratedGoodsIndex;
private boolean available;
private List<Available> availableIndex;
@Indexed(direction = IndexDirection.ASCENDING)
private String store;
private List<Store> storeIndex;
// public ProductBrand() {
// super();
// }
public ProductBrand() {
this.setAvailableIndex(new ArrayList<>());
this.setCategoryIndex(new ArrayList<>());
this.setSubCategoryIndex(new ArrayList<>());
this.setFrozenGoodsIndex(new ArrayList<>());
this.setManufacturerIndex(new ArrayList<>());
this.setOrganicIndex(new ArrayList<>());
this.setRefrigeratedGoodsIndex(new ArrayList<>());
this.setSeasonalIndex(new ArrayList<>());
this.setStoreIndex(new ArrayList<>());
}
public ProductBrand(String id, ProductsBasic basic, String name, String units, double price, double price100g,
String manufacturer, List<Manufacturer> manufacturerIndex, boolean organic, List<Organic> organicIndex,
String category, List<Category> categoryIndex, String subCategory, List<SubCategory> subCategoryIndex,
boolean seasonal, List<Seasonal> seasonalIndex, boolean frozenGoods, List<FrozenGoods> frozenGoodsIndex,
boolean refrigeratedGoods, List<RefrigeratedGoods> refrigeratedGoodsIndex, boolean available,
List<Available> availableIndex, String store, List<Store> storeIndex) {
super();
this.id = id;
this.basic = basic;
this.name = name;
this.units = units;
this.price = price;
this.price100g = price100g;
this.manufacturer = manufacturer;
this.setManufacturerIndex(manufacturerIndex);
this.organic = organic;
this.setOrganicIndex(organicIndex);
this.category = category;
this.setCategoryIndex(categoryIndex);
this.subCategory = subCategory;
this.setSubCategoryIndex(subCategoryIndex);
this.seasonal = seasonal;
this.setSeasonalIndex(seasonalIndex);
this.frozenGoods = frozenGoods;
this.setFrozenGoodsIndex(frozenGoodsIndex);
this.refrigeratedGoods = refrigeratedGoods;
this.setRefrigeratedGoodsIndex(refrigeratedGoodsIndex);
this.available = available;
this.setAvailableIndex(availableIndex);
this.store = store;
this.setStoreIndex(storeIndex);
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public boolean isOrganic() {
return organic;
}
public void setOrganic(boolean organic) {
this.organic = organic;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getSubCategory() {
return subCategory;
}
public void setSubCategory(String subCategory) {
this.subCategory = subCategory;
}
public boolean isSeasonal() {
return seasonal;
}
public void setSeasonal(boolean seasonal) {
this.seasonal = seasonal;
}
public boolean isFrozenGoods() {
return frozenGoods;
}
public void setFrozenGoods(boolean frozenGoods) {
this.frozenGoods = frozenGoods;
}
public boolean isRefrigeratedGoods() {
return refrigeratedGoods;
}
public void setRefrigeratedGoods(boolean refrigeratedGoods) {
this.refrigeratedGoods = refrigeratedGoods;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public void addProduktBrand(ProductBrand productBrand) {
ProductBrand.add(productBrand);
}
public static void add(ProductBrand productBrand) {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public ProductsBasic getBasic() {
return basic;
}
public void setBasic(ProductsBasic basic) {
this.basic = basic;
}
public String getStore() {
return store;
}
public void setStore(String store) {
this.store = store;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUnits() {
return units;
}
public void setUnits(String units) {
this.units = units;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getPrice100g() {
return price100g;
}
public void setPrice100g(double price100g) {
this.price100g = price100g;
}
public List<Manufacturer> getManufacturerIndex() {
return manufacturerIndex;
}
public void setManufacturerIndex(List<Manufacturer> manufacturerIndex) {
this.manufacturerIndex = manufacturerIndex;
}
public List<Organic> getOrganicIndex() {
return organicIndex;
}
public void setOrganicIndex(List<Organic> organicIndex) {
this.organicIndex = organicIndex;
}
public List<Category> getCategoryIndex() {
return categoryIndex;
}
public void setCategoryIndex(List<Category> categoryIndex) {
this.categoryIndex = categoryIndex;
}
public List<SubCategory> getSubCategoryIndex() {
return subCategoryIndex;
}
public void setSubCategoryIndex(List<SubCategory> subCategoryIndex) {
this.subCategoryIndex = subCategoryIndex;
}
public List<Seasonal> getSeasonalIndex() {
return seasonalIndex;
}
public void setSeasonalIndex(List<Seasonal> seasonalIndex) {
this.seasonalIndex = seasonalIndex;
}
public List<FrozenGoods> getFrozenGoodsIndex() {
return frozenGoodsIndex;
}
public void setFrozenGoodsIndex(List<FrozenGoods> frozenGoodsIndex) {
this.frozenGoodsIndex = frozenGoodsIndex;
}
public List<RefrigeratedGoods> getRefrigeratedGoodsIndex() {
return refrigeratedGoodsIndex;
}
public void setRefrigeratedGoodsIndex(List<RefrigeratedGoods> refrigeratedGoodsIndex) {
this.refrigeratedGoodsIndex = refrigeratedGoodsIndex;
}
public List<Available> getAvailableIndex() {
return availableIndex;
}
public void setAvailableIndex(List<Available> availableIndex) {
this.availableIndex = availableIndex;
}
public List<Store> getStoreIndex() {
return storeIndex;
}
public void setStoreIndex(List<Store> storeIndex) {
this.storeIndex = storeIndex;
}
}
这是类的控制器
import java.util.List;
import java.util.Optional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import project.QProductBrand;
import com.querydsl.core.types.dsl.BooleanExpression;
@RestController
@RequestMapping("/productbrand")
public class ProductBrandController {
private ProductBrandRepository productBrandRepository;
public ProductBrandController(ProductBrandRepository productBrandRepository) {
this.productBrandRepository = productBrandRepository;
}
@GetMapping("/all")
public List<ProductBrand> getAll() {
List<ProductBrand> product = this.productBrandRepository.findAll();
return product;
}
@GetMapping("/productbrand/{name}")
public List<ProductBrand> getByName(@PathVariable("name") String name) {
List<ProductBrand> product = this.productBrandRepository.findByName(name);
return product;
}
@PutMapping
public void insert(@RequestBody ProductBrand productBrand) {
this.productBrandRepository.insert(productBrand);
}
@PostMapping
public void update(@RequestBody ProductBrand productBrand) {
this.productBrandRepository.save(productBrand);
}
@DeleteMapping("/{id}")
public void delete(@PathVariable("id") ProductBrand id) {
this.productBrandRepository.delete(id);
}
@GetMapping("/{id}")
public Optional<ProductBrand> getById(@PathVariable("id") String id) {
Optional<ProductBrand> brand = this.productBrandRepository.findById(id);
return brand;
}
@GetMapping("/productBrand/{organic}")
public List<ProductBrand> getByOrganic(@PathVariable("organic") boolean organic) {
List<ProductBrand> brand = this.productBrandRepository.findByOrganic(organic);
return brand;
}
@GetMapping("/productBrand/{manufacturer}")
public List<ProductBrand> getByManufacturer(@PathVariable("manufacturer") String manufacturer) {
List<ProductBrand> brand = this.productBrandRepository.findByManufacturer(manufacturer);
return brand;
}
@GetMapping("/productBrand/{category}")
public List<ProductBrand> getByCategory(@PathVariable("category") String category) {
List<ProductBrand> brand = this.productBrandRepository.findByCategory(category);
return brand;
}
@GetMapping("/productBrand/{seasonal}")
public List<ProductBrand> getBySeasonal(@PathVariable("seasonal") boolean seasonal) {
List<ProductBrand> brand = this.productBrandRepository.findBySeasonal(seasonal);
return brand;
}
@GetMapping("/productBrand/{frozenGoods}")
public List<ProductBrand> getByFrozenGoods(@PathVariable("frozenGoods") boolean frozenGoods) {
List<ProductBrand> brand = this.productBrandRepository.findByFrozenGoods(frozenGoods);
return brand;
}
@GetMapping("/productBrand/{refrigeratedGoods}")
public List<ProductBrand> getByRefrigeratedGoods(@PathVariable("refrigeratedGoods") boolean refrigeratedGoods) {
List<ProductBrand> brand = this.productBrandRepository.findByRefrigeratedGoods(refrigeratedGoods);
return brand;
}
@GetMapping("/productBrand/{available}")
public List<ProductBrand> getByAvailable(@PathVariable("available") boolean available) {
List<ProductBrand> brand = this.productBrandRepository.findByAvailable(available);
return brand;
}
@GetMapping("/recommended")
public List<ProductBrand> getRecommended() {
final boolean isOrganic = true;
final boolean isSeasonal = true;
QProductBrand qBrand = new QProductBrand("ProductBrand");
BooleanExpression filterByOrganic = (qBrand.organicIndex).any().organic.gt(isOrganic);
BooleanExpression filterBySeasonal = (qBrand.seasonalIndex).any().seasonal.gt(isSeasonal);
List<ProductBrand> brand = (List<ProductBrand>) this.productBrandRepository
.findAll(filterByOrganic.and(filterBySeasonal));
return brand;
}
}
这是我的仓库
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface ProductBrandRepository extends MongoRepository<ProductBrand, String>, QuerydslPredicateExecutor<ProductBrand> {
List<ProductBrand> findByName(String name);
List<ProductBrand> findByOrganic(boolean organic);
List<ProductBrand> findBySeasonal(boolean seasonal);
List<ProductBrand> findByFrozenGoods(boolean frozenGoods);
List<ProductBrand> findByRefrigeratedGoods(boolean refrigeratedGoods);
List<ProductBrand> findByAvailable(boolean available);
List<ProductBrand> findByCategory(String category);
List<ProductBrand> findByManufacturer(String manufacturer);
}
这是我的pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.BETAapp</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>project</name>
<description>demo</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-groovy-templates</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180725.0427</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb.morphia/morphia -->
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>0.107</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.querydsl/querydsl-apt -->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-mongodb</artifactId>
<version>4.2.1</version>
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<dependencies>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.2.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/annotations</outputDirectory>
<processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
<logOnlyOnError>true</logOnlyOnError>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Test set: project.StoreBased.ApplicationTests
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 11.036 s <<< FAILURE! - in project.StoreBased.ApplicationTests
contextLoads(project.StoreBased.ApplicationTests) Time elapsed: 0.002 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productBrandController' defined in file [C:\Users\vince\Documents\workspace-spring-tool-suite-4-4.0.1.RELEASE\project(18.11.2018)\target\test-classes\com\project\project\StoreBased\ProductBrandController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productBrandRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Did not find a query class project.StoreBased.QProductBrand for domain class project.StoreBased.ProductBrand!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productBrandRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Did not find a query class project.StoreBased.QProductBrand for domain class project.project.StoreBased.ProductBrand!
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Did not find a query class project.StoreBased.QProductBrand for domain class project.StoreBased.ProductBrand!
Caused by: java.lang.IllegalArgumentException: Did not find a query class project.StoreBased.QProductBrand for domain class project.StoreBased.ProductBrand!
Caused by: java.lang.ClassNotFoundException: project.StoreBased.QProductBrand
此问题的原因:
Your Query Classes are generated in different package (i.e. inside /annotations) and
you are trying to find it from different package.
溶液:
更改输出目录路径(即用于生成“Q”前缀类的标签位置)
<outputDirectory>target/generated-sources/annotations</outputDirectory>
自
<outputDirectory>target/generated-sources/apt</outputDirectory>
删除您的目标文件夹,然后
mvn全新安装
问题内容: 我试图在Netbeans中重构一个大型程序,但我有点迷茫。我从来没有非常模块化,但是现在通过实际学习如何做到这一点来尝试纠正这种情况,并在将来纠正这种情况。不幸的是,我在将某些教程翻译成我的程序时遇到了麻烦。所以我希望这里有人可以帮忙。目前,我正在尝试分解一部分采用特定格式的文件并制成表格的代码。我知道我需要创建一个类并使用它来创建表对象,但是我不确定如何做。我有一个主文件,用于获取文
2周来,我一直在努力寻找此错误的解决方案。你能帮我发生了什么事吗? 以下是错误堆栈跟踪:
问题内容: 我正在使用Spring MVC控制器项目。下面是我的Controller,我声明了一个构造函数,该构造函数专门用于测试。 每当我启动服务器时,都会遇到以下异常- 但是,如果我删除构造函数,那么它将正常工作而不会出现任何问题。我在这里做什么错? 但是,如果我添加此默认构造函数,则它将开始正常工作- 问题答案: 如果要创建自己的构造函数,则必须定义无参数或默认构造函数。 您可以了解为什么需
问题内容: 考虑以下代码: 无需添加方法签名即可编译该代码。(它与同样表现到位,太)。 我理解为什么 可以 安全地运行它,因为实际上不能将其引发在块中,因此不能引发已检查的异常。我有兴趣知道在何处指定此行为。 并非永远都不会达到目标:以下代码也会编译: 但是,如果抛出一个检查的异常,它不会像我期望的那样编译: 在JLS Sec 11.2.2中 ,它说: 一,其抛出的表达式语句(§14.18)具有静
在你可以捕获异常之前,一些代码必须抛出一个异常。任何代码都可能会抛出异常:您的代码,来自其他人编写的包(例如Java平台附带的包)或Java运行时环境的代码。无论是什么引发的异常,它总是通过 throw 语句抛出。 您可能已经注意到,Java平台提供了许多异常类。所有类都是Throwable类的后代,并且都允许程序区分在程序执行期间可能发生的各种类型的异常。 您还可以创建自己的异常类来表示在您编写
我正在尝试用NLTK中的Malt Parser解析句子。当我执行时,它给出了一个错误,退出代码为1。我在终端上执行了java命令,它给出了“未找到”类异常,我不明白现在是怎么了? java-Xmx1024m-jar/usr/local/bin/malt。jar-w/home/abc/maltparser-1.7.2-c engmalt.linear-1.1-i/home/abc/martparse