【java – Spring Tool Suite 3.5.0上的Spring Roo项目】教程文章相关的互联网学习教程文章

java – Spring REST重用嵌套的requstmapping【代码】

我们有一个REST API,用于一些评论.目前,最有趣的URI是:GET /products/1/comments // get all comments of product 1 GET /products/1/comments/5 // get the 5th comment of product 1 GET /products/1/comments/5/user // get the user of the 5th comment GET /products/1/comments/latest // get the latest comment of product 1 GET /products/1/comments/latest/user // get the user of t...

java – Spring依赖注入不使用继承【代码】

我有一个泛型基础dao类,我在其中为所有daos实现了一些泛型方法.<bean id="baseDAO" class="com.db.dao.BaseDao"><property name="sessionFactory" ref="sessionFactory" /> </bean><bean id="userDAO" class="com.db.dao.UserDao"></bean><bean id="notesDAO" class="com.db.dao.NotesDao"></bean>最初,我使用依赖注入将sessionFactory注入每个dao,但后来我实现了一个基础dao,并且还有其他所有daos来扩展这个基础dao. 但是,在更改之...

如何在基于JAVA的spring配置中配置Hibernate Db连接设置【代码】

目前我正在将我的bean创建和配置设置从基于JAVA的spring配置基于XML.我坚持移动数据库设置?如何在基于JAVA的配置文件中编写这些hibernate数据库设置?<beanclass="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="hibernateProperties"><value>hibernate...

java – Spring规范和Pageable【代码】

如何一起使用规范和可分页? personelRepository.java@Query("SELECT e FROM PersonelEntity e ") List<PersonelEntity> findData(Specification<PersonelEntity> test, Pageable pageable);personelService.javapublic List<PersonelEntity> filteredData(Specification<PersonelEntity> filter,Pageable pageable){List<PersonelEntity> filteredData = personelRepository.findData(filter,pageable);return filteredData; }p...

Java – Spring中的Server-Sent Event Client示例【代码】

我们的团队为特定任务开发了服务器发送事件(SSE). 我正在尝试构建一个客户端来监听来自我们服务器的事件流.我有点使用Jersey库for Java来做到这一点.但是,由于我们的大多数客户端代码都使用Spring,因此我想举例说明如何使用Spring完成此操作. 我在Spring的服务器端找到了很多关于SSE的例子.但是,我无法找到客户端的任何文档. Spring是否支持客户端的SSE?如果是,我可以举例说明如何使用Spring实现以下功能…… 向我们的服务器发送H...

java – spring jpa auditing lastmodifiedby和lastmodifiedDate都可以,但createdBy和createdDate注释总是为null【代码】

我正在尝试设置(作为一个java初学者)spring jpa审计现在几小时/几天…而且我开始变得非常沮丧,因为我找不到问题.我真的很感激一些帮助. @ LastModifiedBy和@LastModifiedDate注释正在工作,但@CreatedBy和@CreatedDate始终为NULL. 这是sql查询调试输出:2017-06-16 16:40:39 [main] DEBUG n.t.d.l.l.SLF4JQueryLoggingListener n.t.d.s.SLF4JLogUtils writeLog – 名称:,时间:0,成功:False,类型:Prepared,Batch:False,QuerySi...

java – 通过spring休息api【代码】

我必须使用条件选择查询从表中获取MySQL中的所有数据,其中字段为isdeleted = 0,location = 1.我怎样才能在存储库和访问管理器中实现它.public interface FoodCourtRepository extends JpaRepository<FoodCourtEntity, Long> {List<FoodcaseEntity> findByIsdeleted(Boolean isDeleted); }在访问管理器中public List<FoodcaseDO> getAllFoodCourt() {List<FoodcaseEntity> foodCaseList = foodcourtRepository.findByIsdeleted(fal...

java – Spring AspectJ从ProceedingJoinPoint获取方法注释【代码】

我有一个方面来处理具有自定义注释的所有方法. 注释有一个枚举参数,我必须得到方面的值:@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Monitored {MonitorSystem monitorSystem(); }我的情况与question非常相似,并且接受的答案适用于没有实现接口的Spring bean. 方面:@Aspect @Component public class MonitorAspect {@Around("@annotation(com.company.project.monitor.aspect.Monitored...

java – Spring @ResponseStatus返回空响应【代码】

在我的Spring API中,我想用Spring的注释@ResponseStatus处理来自诸如create,put和delete之类的操作的响应.每个端点都能正常工作,但它们始终返回空响应. 为什么来自带注释的端点的响应是空的? 控制器:import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.http.HttpStatus;@RestController @RequestMapping(value = "/v1/portfolios") public class PortfolioController {@RequestMapping...

java – Spring – 基于属性注入依赖关系【代码】

Spring Boot是否有办法使用配置文件中提供的类名和构造函数属性注入依赖项? 例如,我有两个版本的通用接口,IFileStore,FileStoreA和FileStoreB.我希望能够在application.yml文件中定义我应该使用哪些. 我知道我可以这样做:@Value("${fileStore.class}") private String fileStoreClassName;@Bean public IFileStore fileStore() {switch(fileStoreClassName) {case "FileStoreA":return new FileStoreA();case "FileStoreB":retur...

java – Spring中的自定义Http状态代码【代码】

我正在使用Spring Boot,我在我的业务逻辑代码中使用Exception Classes.一个可能看起来像这样:@ResponseStatus(HttpStatus.BAD_REQUEST) public class ExternalDependencyException extends RuntimeException {public ExternalDependencyException() {super("External Dependency Failed");}public ExternalDependencyException(String message) {super(message);}}那么现在有Exception,其中没有预定义的Http Status代码是合适的,所...

java – Spring boot:根据环境变量排除自动配置【代码】

在spring boot中,我们可以排除特定的自动配置类,以便永远不会应用它们.基于注释的配置示例:@SpringBootApplication(exclude = OneConfiguration.class)我想要的是提供一个环境变量,其值将决定一些将被排除的自动配置.任何想法如何实现?解决方法:创建类扩展环境变量的条件检查值:public class AutoConfigurationCondition extends Condition {@Overridepublic boolean matches(ConditionContext context, AnnotatedTypeMetadata ...

java – spring CORS和angular not working:HTTP状态码403错误【代码】

我是角度和弹簧安全的新手.当我尝试使用基本身份验证从角度登录表单页面登录到其余端点时,我遇到CORS问题.我的Angular代码在http://localhost:4200运行,休息结束点在http://localhost:8181.我的angular login-form尝试向我在登录控制器中指定的http://localhost:8181/token发出请求.即使我在服务器端添加了cors配置,我也会收到此错误: – 无法加载http://localhost:8181/token:对预检请求的响应未通过访问控制检查:请求的资源上...

Java Spring Patch RFC-6902即时类型转换异常【代码】

我有修补问题,这与将String值转换为相应的类型有关.当我尝试修补“Locale”类型(或原语)时,它可以工作.但它失败了即时 实体:@JsonIgnore @Field("locale") private Locale locale;@JsonIgnore @Field("dateOfBirth") private Instant dateOfBirth;@JsonIgnore public Locale getLocale() {return this.locale; }@JsonIgnore public void setLocale(Locale locale) {this.locale = locale; }@JsonIgnore public Instant getDateOfB...

java – Spring Boot – 当我调用API时,它会给出404错误【代码】

我创建了一个spring boot应用程序.当我在嵌入式tomcat中部署jar文件并调用测试API时,它会产生404错误.我可以知道它为什么会出错吗? 主要课程package com.telematics.fleet;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan;@SpringBootApplication @ComponentScan(basePackages={"com.te...