Spring

Spring rest controller returns 404

99封情书 提交于 2021-02-10 22:53:14
问题 My rest controller ,which is written by spring, returns 404 but when I debug over Eclipse , I see that it comes to my method and returns result but result is still 404. Controller is like: @RestController @RequestMapping("admin/context") public class ApplicationAdmin { @Autowired private ApplicationContextService applicationContextService; @RequestMapping(value="/monitor",method = RequestMethod.GET, produces = "application/json") @ResponseStatus(HttpStatus.OK) public Response monitorContexts(

Spring Boot Quartz 分布式集群任务调度实现

不打扰是莪最后的温柔 提交于 2021-02-10 22:48:39
Spring Boot Quartz 主要内容 Spring Scheduler 框架 Quartz 框架,功能强大,配置灵活 Quartz 集群 mysql 持久化定时任务脚本(tables_mysql.sql) 介绍 在工程中时常会遇到一些需求,例如定时刷新一下配置、隔一段时间检查下网络状态并发送邮件等诸如此类的定时任务。 定时任务本质就是一个异步的线程,线程可以查询或修改并执行一系列的操作。由于本质是线程,在 Java 中可以自行编写一个线程池对定时任务进行控制,但这样效率太低了,且功能有限,属于重复造轮子。 分布式任务调度应用场景 Quartz的集群功能通过故障转移和负载平衡功能为您的调度程序带来高可用性和可扩展性。 调度程序中会有很多定时任务需要执行,一台服务器已经不能满足使用,需要解决定时任务单机单点故障问题。 用Quartz框架,在集群环境下,通过数据库锁机制来实现定时任务的执行;独立的 Quartz 节点并不与另一其的节点或是管理节点通信。 Spring Scheduler 实现定时任务 1.定义 Task 类 /** * Spring Scheduled示例 */ @Component public class ScheduledTask { private static final SimpleDateFormat dateFormat = new

How does Spring multipart file upload exactly work?

余生颓废 提交于 2021-02-10 22:28:09
问题 I develope a fileserver that has to handle large file uploads (>1G B) with spring boot. How can I implement the upload when I do not want to use the main memory? This is my code: final String id = GenerationHelper.uuid(); final File newFile = new File(id); LOG.info("New file: " + id + " with size " + content.getSize()); if (!content.isEmpty()) { FileInputStream in = null; FileOutputStream out = null; long totalBytes = 0; try { in = (FileInputStream) content.getInputStream(); out = new

How does Spring multipart file upload exactly work?

可紊 提交于 2021-02-10 22:20:35
问题 I develope a fileserver that has to handle large file uploads (>1G B) with spring boot. How can I implement the upload when I do not want to use the main memory? This is my code: final String id = GenerationHelper.uuid(); final File newFile = new File(id); LOG.info("New file: " + id + " with size " + content.getSize()); if (!content.isEmpty()) { FileInputStream in = null; FileOutputStream out = null; long totalBytes = 0; try { in = (FileInputStream) content.getInputStream(); out = new

How to return a List inside this bounded generic method?

大兔子大兔子 提交于 2021-02-10 20:14:21
问题 I have class Response public class Response<T extends ResponseData> { private final T data; //other fields, getters, setters ... } and the empty interface ResponseData: public interface ResponseData { } It takes any object as data but this object must implement the "empty" interface which I created just to force all classes returned inside "data" element be of same super type Now the problem is that I need to return a List inside the data element, but: I don't find it clean to create a

JAR冲突问题的解决

心已入冬 提交于 2021-02-10 19:48:57
今天碰到群里小伙伴问,线上程序好像有多个不同版本的Netty包,怎么去看到底加载了哪一个? 在说如何看之前,先来说说,当你开始意识到项目里有多个不同版本的Jar包,都是因为遇到了这几个异常: 1、java.lang.NoSuchMethodException:自己代码中调用了某个方法,因为加载了其他版本的jar,这个版本正好没这个方法。 2、java.lang.NoClassDefFoundError:编译时候是好的,但是运行的时候,因为加载的jar版本问题,没有这个类。 3、java.lang.ClassNotFoundException:在动态加载某个Class的时候,因为要加载的jar不是正确的版本,而导致找不到这个类。 当你在本地运行ok,但到服务器上发现出现这些错误的时候,就要意识到很可能是jar冲突了(有相同依赖存在多个版本)。这个问题往往也会有这样的表现:多实例部署的时候,有的实例是好的,有的实例则不行。 查看加载的类和方法 根据之前分析的异常种类,我们可以去运行中的现场确认当前加载的问题。 这里我们可以使用阿里开源的Arthas工具,如果第一次用,那么按下面操作先安装再运行: curl -O https://arthas.aliyun.com/arthas-boot.jar java -jar arthas-boot.jar 运行好之后

@ManagedProperty equivalent in Spring

*爱你&永不变心* 提交于 2021-02-10 18:58:25
问题 I am using Spring for my DI. Is there an equivalent of @ManagedProperty? I want to inject the value from one view scoped bean into another one on the next page. e.g @Component @Scope("view") public class Page1Bean(){ private String value; } @Component @Scope("view") public class Page2Bean(){ @ManagedProperty(value = #{page1Bean}") //doesnt work in Spring private Page1Bean bean; } 回答1: @Resource or @Autowired should work. @Resource is the Java EE implementation, @Autowired is the spring

@ManagedProperty equivalent in Spring

北城余情 提交于 2021-02-10 18:57:07
问题 I am using Spring for my DI. Is there an equivalent of @ManagedProperty? I want to inject the value from one view scoped bean into another one on the next page. e.g @Component @Scope("view") public class Page1Bean(){ private String value; } @Component @Scope("view") public class Page2Bean(){ @ManagedProperty(value = #{page1Bean}") //doesnt work in Spring private Page1Bean bean; } 回答1: @Resource or @Autowired should work. @Resource is the Java EE implementation, @Autowired is the spring

@ManagedProperty equivalent in Spring

左心房为你撑大大i 提交于 2021-02-10 18:56:48
问题 I am using Spring for my DI. Is there an equivalent of @ManagedProperty? I want to inject the value from one view scoped bean into another one on the next page. e.g @Component @Scope("view") public class Page1Bean(){ private String value; } @Component @Scope("view") public class Page2Bean(){ @ManagedProperty(value = #{page1Bean}") //doesnt work in Spring private Page1Bean bean; } 回答1: @Resource or @Autowired should work. @Resource is the Java EE implementation, @Autowired is the spring

@ManagedProperty equivalent in Spring

旧时模样 提交于 2021-02-10 18:56:38
问题 I am using Spring for my DI. Is there an equivalent of @ManagedProperty? I want to inject the value from one view scoped bean into another one on the next page. e.g @Component @Scope("view") public class Page1Bean(){ private String value; } @Component @Scope("view") public class Page2Bean(){ @ManagedProperty(value = #{page1Bean}") //doesnt work in Spring private Page1Bean bean; } 回答1: @Resource or @Autowired should work. @Resource is the Java EE implementation, @Autowired is the spring