如何在SpringBoot下关闭JPA for SpringBatch(How to turn off JPA for SpringBatch under SpringBoot)
我们有一个使用Spring Integration和Spring Batch的Spring Boot应用程序。 我们在轮询器中放置一个文件并处理它。 该过程将记录插入到数据库中,然后将它们读出来进行一些处理并写入文件。 假设有10条记录。 我们第一次读取10条记录并写入10条记录。 在不停止服务器的情况下,我们通过数据库上的SQL客户端删除所有记录,再次运行相同的文件,我们得到10条记录,其中20条记录被读取。 我相信有一些JPA或缓存与数据源进行。 我们已经尝试关闭JPA和缓存的几个自动配置选项,但是我们没有找到正确的配置选项来关闭缓存。
为问题添加更多细节。
基本上我们有cron调度器,它有一个FileHandler。 这个handleFile方法我们有以下几点。
public File handleFile(File file) throws Throwable { JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(); Job job = (Job) appContext.getBean("processInitialFileJob"); JobExecution jb = jobLauncher.run(job, jobParametersBuilder.toJobParameters()); .... }
我们可以对上面的代码做些什么来确保它具有新的JPA会话或根本不使用JPA会话? 这项工作需要每次从数据库读取,而不是数据库的缓存表示。
We have a Spring Boot application that uses Spring Integration and Spring Batch. We drop a file in the poller and it processes. This process inserts records into a database and then reads them back out does some processing and writes a file. Let's say there are 10 records. The first time we get 10 records read and 10 written. Without stopping the server, we delete all the records through a SQL client on the database, run the same file again and we get 10 records read with 20 written. I believe there is some JPA or caching going on with the datasource. We've tried turning off several auto configuration options for JPA and caching but we haven't found the right configuration option to turn off caching.
Adding a bit more detail to the question.
Basically we have cron scheduler that has a FileHandler. This the handleFile methods we have the following.
public File handleFile(File file) throws Throwable { JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(); Job job = (Job) appContext.getBean("processInitialFileJob"); JobExecution jb = jobLauncher.run(job, jobParametersBuilder.toJobParameters()); .... }
What can we do to the code above to ensure that it has a new JPA session or not use the JPA session at all? This job needs to read from the database each time and not a cached representation of the database.
原文:https://stackoverflow.com/questions/43374433
最满意答案
您必须使用proxy_pass代理远程服务器。 例:
header("Content-Disposition: attachment; filename= 'asd.zip'"); header("Content-Type: application/octet-stream"); header('X-Accel-Redirect: /upload/domain.com/path/to/file.zip'); header("X-Accel-Buffering: yes"); header("X-Accel-Limit-Rate: 102400");
Nginx的
location ~* ^/upload/(.*?)/(.*) { internal; set $download_host $1; set $download_uri $2; proxy_pass http://$download_host/$download_uri; }
You have to use a proxy_pass to proxy to the remote server. Example:
header("Content-Disposition: attachment; filename= 'asd.zip'"); header("Content-Type: application/octet-stream"); header('X-Accel-Redirect: /upload/domain.com/path/to/file.zip'); header("X-Accel-Buffering: yes"); header("X-Accel-Limit-Rate: 102400");
Nginx
location ~* ^/upload/(.*?)/(.*) { internal; set $download_host $1; set $download_uri $2; proxy_pass http://$download_host/$download_uri; }
相关问答
更多-
Nginx重定向登录(Nginx redirect to sign in)[2022-06-19]
首先转到environment.rb ENV['RAILS_RELATIVE_URL_ROOT'] = "/nix/" 第二个config.ru map '/nix/' do run App::Application end 接下来是nginx.conf location /nix/ { proxy_pass http://example:7458/nix/; proxy_set_header Host $host; } 输入http://example:7456/nix/sign_i ... -
用Rails创建带X-Accel-Redirect的POST请求?(Creating a POST request with X-Accel-Redirect with Rails?)[2021-07-10]
我敢肯定,你不能用nginx开箱即用。 这个功能的确是为加速文件下载而设计的,所以它非常专注于GET请求。 也就是说,你可以用lua模块做一些事情。 在编译包含模块的nginx版本后,类似这样的工作可能会奏效。 Ruby代码: def proxy_video(path) self.status = 200 response.headers["X-Accel-Redirect"] = "/proxy/#{path}" response.headers["X-Accel-Post-Body"] = ... -
如果要指示Web浏览器应下载资源而不是显示它,请尝试使用RFC 6266中所述的Content-Disposition标头。 例如,以下响应标头将告诉浏览器下载文件: Content-Disposition: attachment 您还可以通过此标头为下载的文件指定文件名(如果它与URL中的最后一个路径组件不同): Content-Disposition: attachment; filename=foo.pdf 查看Nginx文档 ,此响应标头应与您正在使用的X-Accel-Redirect功能一起正 ...
-
好的 - 这里有几个问题: 1)根据nginx开发人员的说法,将某个位置内的root用户设置为一个不好的IDEA 。 2)用于告诉Nginx这是内部重定向的内部URL不应该暴露给用户。 3)我看不到你的download.php文件来自哪里,所以我改变了你的根位置块以使用try_files,所以对/download.php的请求将由该文件而不是index.php提供。 您的项目应按以下方式进行布局: project\ html - this is the root of your website ...
-
将自定义HTTP标头添加到nginx X-Accel-Redirect(Adding custom HTTP headers to nginx X-Accel-Redirect)[2023-09-07]
使用add_header Content-MD5 $upstream_http_content_md5; 由于X-Accel-Redirect导致内部重定向,因此nginx不会发送返回的标头,但会将它们保存在$upstream_http_...变量中。 所以你可以使用它们。 Use add_header Content-MD5 $upstream_http_content_md5; Since X-Accel-Redirect causes internal redirect nginx will not ... -
您必须使用proxy_pass代理远程服务器。 例: header("Content-Disposition: attachment; filename= 'asd.zip'"); header("Content-Type: application/octet-stream"); header('X-Accel-Redirect: /upload/domain.com/path/to/file.zip'); header("X-Accel-Buffering: yes"); header("X-Accel- ...
-
该错误是由于nginx配置文件中的规则冲突造成的。 所以,解决方案是: location ^~ /protected_files { # ^~ needed according to the [nginx docs][1] to avoid nginx to check more locations internal; alias /path/to/static/files/directory; } #avoid processing of calls to unexisting stat ...
-
显然它是每秒字节数。 资源 Apparently it is bytes per second. Source
-
我不知道为什么我以前无法上班。 也许Nginx Wiki文档错了? 这就是我解决它的方式: 在nginx / sites-available / default中: location /issues { root /home/ubuntu; internal; } 在views.py中: file_name = 'some.zip' url = '/issues/' + file_name response = HttpResponse() response['Co ...
-
Nginx覆盖Rails 4 X-Accel-Redirect网址上的内容类型(Nginx override Content type on Rails 4 X-Accel-Redirect urls)[2022-04-20]
经过一些实验,事实证明我必须传递content_type来render :nothing可以使x-accel-redirect识别内容类型而且它不关心headers['Content-type'] 现在这段代码运行正常 render :nothing => true, :content_type => MIME::Types.type_for(params[:format]).first.content_type After some experimenting, it turns out that i ...