我正在尝试建立一个与龙目岛的项目,这是我有依赖。
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.social:spring-social-facebook")
compile("org.springframework.social:spring-social-twitter")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("junit:junit")
compile("org.springframework.boot:spring-boot-devtools")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("mysql:mysql-connector-java")
compileOnly("org.projectlombok:lombok:1.16.10")
}我能够包含anotations,并且我已经在编辑器中包含了lombok。我甚至可以使用lombok编译代码,并调用lombok生成的方法。
这是我的实体:
@Data
@Entity
@Table(name = "TEA_USER", uniqueConstraints = {
@UniqueConstraint(columnNames = { "USR_EMAIL" }),
@UniqueConstraint(columnNames = { "USR_NAME" })
})
public class User {
@NotNull
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="USR_ID")
private long id;
@NotNull
@Column(name="USR_FNAME")
private String firstName;
@NotNull
@Column(name="USR_LNAME")
private String lastName;
@NotNull
@Min(5)
@Max(30)
@Column(name="USR_NAME")
private String username;
@Column(name="USR_EMAIL")
private String email;
@Min(8)
@NotNull
@Column(name="USR_PASSWORD")
private String password;
}这是一个编译得很好的函数:
@PostMapping("/registration/register")
public String doRegister (@ModelAttribute @Valid User user, BindingResult result){
user.getEmail();
System.out.println(user.getFirstName());
if (result.hasErrors()) {
return "register/customRegister";
}
this.userRepository.save(user);
return "register/customRegistered";
}但当我运行bootRun并尝试访问函数时,这是我得到的异常:
org.springframework.beans.NotReadablePropertyException: Invalid property 'firstName' of bean class [com.lucasfrossard.entities.User]: Bean property 'firstName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?但是,如果我手动包含setter和getter,就可以很好地工作。我不知道发生了什么,也不知道如何修复它。有什么想法吗?
发布于 2018-11-09 00:47:40
使用最新的Lombok 1.18很简单。不需要io.franzbecker.gradle-lombok插件。我的项目中的示例依赖项:
dependencies {
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.springframework.social:spring-social-facebook"
implementation "org.springframework.social:spring-social-twitter"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
testImplementation "org.springframework.boot:spring-boot-starter-test"
runtimeClasspath "org.springframework.boot:spring-boot-devtools"
runtime "mysql:mysql-connector-java"
// https://projectlombok.org
compileOnly 'org.projectlombok:lombok:1.18.4'
annotationProcessor 'org.projectlombok:lombok:1.18.4'
}其他建议:
testCompile("junit:junit")不是必需的,因为contains JUnit.implementation或api的配置是spring-boot-starter-test“Starter”,而不是compile (从Gradle 3.4开始)。How do I choose the right one?devtools使用compile配置。来自Developer Tools指南的提示:在Maven中将依赖项标记为可选或在Gradle中使用自定义developmentOnly配置(如上所示)是一种最佳实践,它可以防止将devtool过渡到使用您的项目的其他模块。
发布于 2016-11-08 06:53:35
在与此斗争了一段时间后,我发现这个插件可以做到这一点:
https://github.com/franzbecker/gradle-lombok
我的gradle文件看起来像这样:
buildscript {
repositories {
maven { url "https://repo.spring.io/libs-milestone" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
classpath 'org.springframework:springloaded:1.2.6.RELEASE'
}
}
plugins {
id 'io.franzbecker.gradle-lombok' version '1.8'
id 'java'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-accessing-facebook'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-milestone" }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
// compile("org.projectlombok:lombok:1.16.10")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.social:spring-social-facebook")
compile("org.springframework.social:spring-social-twitter")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("junit:junit")
compile("org.springframework.boot:spring-boot-devtools")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("mysql:mysql-connector-java")
}
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}
bootRun {
addResources = true
jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
}我以前遇到过这个插件,但我做错了什么,它不能工作。我很高兴它现在起作用了。
谢谢!
发布于 2020-06-22 21:48:56
如果您使用的是Eclipse或其分支之一(我使用的是Spring Tool Suite 4.5.1.RELEASE,同样的步骤也适用于其他版本),那么您需要做的就是:
build.gradle中的
依赖项{ compileOnly 'org.projectlombok:lombok‘annotationProcessor 'org.projectlombok:lombok’}
lombok-"version".jar将显示在项目的项目和外部Dependencies中
lombok-"version".jar > Run As > Java Application (类似于双击实际jar或在命令行上运行java -jar lombok-"version".jar )。lombok.jar复制到您的集成开发环境的根文件夹中。更新:
1Lombok之后,使用4.11.1.RELEASE,我仍然引用我为安装year+而编写的内容。
https://stackoverflow.com/questions/40475910
复制相似问题