【java-Spring Data Jpa-ManyToMany-删除联接表的实体】教程文章相关的互联网学习教程文章

java-Spring JPA Projection包括链接【代码】

给定一个简单的Event模型,该模型具有一组Booking对象: 事件:@Entity public class Event {@Id@GeneratedValue(strategy=GenerationType.AUTO)private Long eventId;private Date start;private Date end;private String title;@OneToMany(mappedBy="event")private Set<Booking> Bookings;protected Event() {// for JPA}// Getters and setters omitted for brevity }预订:@Entity public class Booking { @Id@GeneratedValue(...

java-Spring JPA休眠重复【代码】

嗨,我是这个世界的新手.我正在使用Spring JPA Hibernate进行自己的应用程序.我有一个实体类.它可以正常工作,但可以复制属性.我的代码如下所示:import java.util.Date;import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.validation.constraints...

java-Spring AOP-在调用setter之前获取旧的字段值【代码】

亲爱的所有人,我目前正在将Spring AOP(v4)和AspectJ与Load-Time-Weaver一起使用. 我目前正在寻找一种将脏标志机制添加到我的bean中的方法.因此,尽管我在使用bean的setter之前使用AOP来调用方法.我已经实现了,但是如何在修改之前访问旧的字段值?还是有一种获取字段名称的方法,以便我可以在调用setter之前先调用getter? 有人可以在这里为我提供一些示例,如何使切入点/建议看起来像参数一样传递?@Aspect public class MyAspect {@B...

java-Spring MVC @RestController->无论我做什么,都会在“ 400 Bad Request”中放入结果【代码】

我有一个Spring RestController,当我从中获取数据时,它工作得很好,但是当我尝试放入非常相同的数据时,我得到了400 Bad Request. 这是我的控制器仍然可以正常工作的最简单版本(我省略了GET方法):@RestController @RequestMapping("/configuration/ledstrips/{name}/display") public class DisplayController {@ResponseBody@RequestMapping(method = RequestMethod.PUT, produces = { "application/hal+json" })public DisplayRes...

java-Spring dataSource返回null【代码】

我正在尝试将MySQL数据库与Spring连接.我也想将DataSource setter方法与@Autowired一起使用.每次运行代码时,DataSource始终返回null. 错误:HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException有人可以告诉我我的代码有什么问题吗?请在下面找到我的代码. CustomerController.javapackage com.springapp.controller;import com.springapp.beans.Customer; import com.springapp.se...

java-Spring安全角色无法转换为授予的权限【代码】

User.javapublic class User implements Serializable{@Id@Size(min=5,max=15)@Column(name="username", unique=true)private String username;@OneToMany(mappedBy="user")private Collection<Role> roles;public User(User user) {this.username=user.username;this.roles=user.getRoles();} }角色.javapublic class Role implements Serializable{@Id@GeneratedValue(strategy=GenerationType.AUTO)private int id;private Stri...

java-Spring:检查给定的端点是否存在【代码】

就像标题一样.我想知道,是否有简单的方法来检查给定的路径是否可以转换为任何控制器中存在的(API)端点. 我有一个具有最高优先级的自定义过滤器,并且如果给定的请求不会产生任何结果(端点不存在),我想返回404状态代码.解决方法:看一下RequestMappingHandlerMapping类,尤其是它的getHandlerMethods方法. 从文档:public Map<T,HandlerMethod> getHandlerMethods() Return a (read-only) map with all mappings and HandlerMethod’s....

java-Spring无法使用空键返回JSON响应【代码】

以下是我编写的代码.@RequestMapping(value = "/getData", method = RequestMethod.GET) public @ResponseBody Map<String,String> test() throws IOException { Map<String,String> map = new HashMap<String,String>(); map.put("key","value"); map.put(null, "Key's Value"); //**This highlighted code causing the problem, if I remove this then it works fine.** return map; }当我点击URL localhost:8080 / ...

java-Spring Boot忽略application.yml中的数据源URL【代码】

我发现Spring Boot会默默忽略通过org.springframework.boot.autoconfigure.jdbc.DataSourceProperties加载的所有数据源属性. 我的application.yml包含:spring:datasource:name: this is not ignoredurl: this is ignored在启动过程中,我看到以下行:o.s.j.d.e.EmbeddedDatabaseFactory : Creating embedded database 'this is not ignored'调试显示DataSourceProperties对象在调用getUrl期间未设置任何属性(调试还显示抛出...

java-Spring Security Kerberos AD,校验和失败【代码】

我正在尝试使用http://docs.spring.io/spring-security-kerberos/docs/1.0.1.RELEASE/reference/htmlsingle/#samples-sec-server-win-auth中所述的带有Active Directory凭据的Spring Security Kerberos.我想说的是,我已经把大部分东西都弄下来了(SPN,密钥表等).现在我的校验和失败.假设我更改了主体名称,则会收到AES加密错误. 我在RHEL 6和Oracle Java 1.8 JCE上使用Spring Boot样本来自https://github.com/spring-projects/spring...

java-Spring Boot测试:测试通过,但不应通过(假肯定)【代码】

我有带有测试的Spring Boot项目,它不会失败(但应该). 我是在做错什么,还是Spring的问题? 作为一个小示例,我创建了一个小项目,其中包含2个实体(用户和类别)和一个具有DELETE方法(https://github.com/sk8ter/demo)的Controller类. 类别实体的ID为不带级联选项的用户实体,因此在删除具有类别的用户时应该失败:@Entity @Table(name = "user") public class User {@Id@GeneratedValueprivate long id;private String name;... }@Entit...

java-Spring Boot Security:使用自定义身份验证过滤器的异常处理【代码】

我正在使用Spring Boot Spring Security(java config).我的问题是旧的,但是我发现的所有信息都已部分过时,并且大部分包含xml-config(很难或什至不可能适应一段时间) 我正在尝试使用令牌(不存储在服务器端)进行无状态身份验证.长话短说-这是JSON Web令牌认证格式的简单模拟.我在默认一个之前使用了两个自定义过滤器: > TokenizedUsernamePasswordAuthenticationFilter,它在之后创建令牌在入口点(“ / myApp /登录”)成功认证> Toke...

java-Spring中的Bean创建异常【代码】

我正在尝试自动装配在另一个项目中声明的类,但是却遇到了运行时异常,而不是编译时异常.如果我删除了自动装配并使用新实例创建了一个对象,则该实例可以完美运行. 我收到以下错误:ErrorSEVERE: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getThreshold': Injection of autowired dependencies failed; nested exception is org.springframework.beans.fa...

java-Spring Boot和Hibernate 5的类加载错误【代码】

我最近将基于Spring Boot的应用程序从Hibernate 4升级到了Hibernate5.此后,我观察到类加载问题.显然,休眠类和我的域类是由两个不同的类加载器加载的.仅当我使用Spring DevTools和Hibernate 5启动应用程序时,才会发生这种情况.DevTools / Hibernate 4,mvn spring-boot:run / Hibernate 5组合可以正常工作. 可以使用以下简单的Spring Boot应用程序重现该问题(完整的Eclipse项目可用here)@Entity public class Employee implements S...

java-Spring属性配置语法?【代码】

我在Spring XML文件中遇到了一种奇怪的语法:<bean id="mySessionFactory" class="my.thingy.session.SessionFactoryImpl"><property name="myPropertyName"><!-- WHAT IS THIS VALUE? --><value>${process.file.thing:propname.server}</value></property> </bean>我对${value1:value2}占位符的语法不熟悉-值1在那里做的第一个值是什么?它是类路径,程序包名称,文件夹名称还是什么?我已经搜索了对此的一些解释,但是它显然没有记...