想知道@VersionSpring Data REST中的注释如何用于ETag,我没有看到由于某种原因填充了ETag
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Venue implements Serializable {
private static final long serialVersionUID = -5516160437873476233L;
private Long id;
...
// other properties
private Long version;
private Date lastModifiedDate;
// getters & setters
@JsonIgnore
@LastModifiedDate
public Date getLastModifiedDate() {
return lastModifiedDate;
}
@Version
@Column
public Long getVersion() {
return version;
}
Run Code Online (Sandbox Code Playgroud)
通过文档,这应该给我一个Etag价值?如图书馆的片段所示
protected HttpHeaders prepareHeaders(PersistentEntity<?, ?> entity, Object value) {
// Add ETag
HttpHeaders headers = ETag.from(entity, value).addTo(new HttpHeaders());
// Add Last-Modified
AuditableBeanWrapper wrapper = getAuditableBeanWrapper(value); …Run Code Online (Sandbox Code Playgroud) 我正在编写一个非Java项目的Gradle构建,用于将现有目录和tar存档组合成.tar.gz如果我使用这样的定义,tar任务会跳过:
task archive(dependsOn: 'initArchive',type: Tar) << {
baseName = project.Name
destinationDir = new File(project.buildDir.path+'/installer')
compression = Compression.GZIP
from (archiveDir)
doLast{
checksum(archivePath)
}
}
Run Code Online (Sandbox Code Playgroud)
这是控制台输出
:jenkins-maven-sonar:archive
Skipping task ':jenkins-maven-sonar:archive' as it has no source files.
:jenkins-maven-sonar:archive UP-TO-DATE
BUILD SUCCESSFUL
Total time: 9.056 secs
Run Code Online (Sandbox Code Playgroud)
当我尝试使用tar任务作为方法时,它失败抱怨无法找到方法
task archive(dependsOn: 'initArchive') << {
tar{
baseName = project.Name
destinationDir = new File(project.buildDir.path+'/installer')
compression = Compression.GZIP
from (archiveDir)
doLast{
checksum(archivePath)
}
}
}
FAILURE: Build failed with an exception.
* Where:
Build file '/home/anadi/Code/da-ci-installers/build.gradle' line: 29
* …Run Code Online (Sandbox Code Playgroud) 我正在尝试部署在puma和jruby上运行的rails应用程序.Procfile如下
web: bundle exec puma -C config/puma.rb -p $PORT -e $RACK_ENV
Run Code Online (Sandbox Code Playgroud)
Puma放置的配置
配置/ puma.rb
if ENV['RACK_ENV'] != 'production' || ENV['RAILS_ENV'] != 'production'
workers Integer(ENV['PUMA_WORKERS'] || 4)
end
threads Integer(ENV['MIN_THREADS'] || 1), Integer(ENV['MAX_THREADS'] || 4)
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
preload_app!
on_worker_boot do
# worker specific setup
ActiveSupport.on_load(:active_record) do
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['pool'] = ENV['MAX_THREADS'] || 16
ActiveRecord::Base.establish_connection(config)
end
end
Run Code Online (Sandbox Code Playgroud)
我对工人进行条件初始化的原因是因为Heroku抱怨(或者可能是Puma)工作模式不适用于JRuby和Windows; 无论如何,
我在heroku上注意到的奇怪行为是(不像)我的本地环境,群集的Puma实例启动时没有任何问题,并且拾取两个不同的端口来绑定,即3000和5000.
然而,在生产即Heroku这导致崩溃
2014-06-23T08:50:54.545724+00:00 heroku[web.1]: State changed from crashed to starting
2014-06-23T08:51:02.510184+00:00 app[web.1]: …Run Code Online (Sandbox Code Playgroud) 我在春天写了一个小应用程序来学习java配置,因为我已经被同行唠叨了一段时间来升级我们的应用程序;-),一个简单的待办事项列表应用程序,它具有安全性和web mvc配置,JPA用于持久性,所有通过java配置.我在尝试运行应用程序时遇到了问题.scurity配置和JPA等工作正常但在成功拦截受保护的URL后我得到一个空视图
主Web应用程序初始化程序类扩展 AbstractAnnotationConfigDispatcherServletInitializer
public class WiggleWebApplicationInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { WiggleApplicationConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WiggleWebAppConfig.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
protected void registerDispatcherServlet(ServletContext servletContext) {
super.registerDispatcherServlet(servletContext);
servletContext.addListener(new HttpSessionEventPublisher());
}
@Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
return new Filter[] { characterEncodingFilter };
}
}
Run Code Online (Sandbox Code Playgroud)
在WiggleApplicationConfig进口安全,JPA和社会
@Configuration …Run Code Online (Sandbox Code Playgroud) 我有一个控制器映射用于处理上传的文件
控制器
@RequestMapping(value = "/careers/pursue", method = RequestMethod.POST)
public Callable<String> pursue(
final @RequestParam("g-recaptcha-response") String captchaResponse,
final @RequestParam("file") MultipartFile file,
final @ModelAttribute("jobapplication") @Valid JobApplication application, final BindingResult bindingResult,
final Model model)
Run Code Online (Sandbox Code Playgroud)
形式
<form name="jobsForm" id="jobsForm" novalidate="novalidate" action="#" th:action="@{/careers/pursue}"
th:object="${jobapplication}" method="post" enctype="multipart/form-data">
<div class="control-group form-group">
<div class="controls">
<label>First Name:</label>
<input type="text" class="form-control" id="firstName" th:field="*{firstName}" required="required" data-validation-required-message="Please enter your name." />
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Last Name:</label>
<input type="text" class="form-control" id="lastName" th:field="*{lastName}" required="required" data-validation-required-message="Please enter your name." /> …Run Code Online (Sandbox Code Playgroud) 大家,
我正面临一个奇怪的问题,包括jsp页面中的脚本标签.在我包含的三个脚本中,只有第一个脚本在最后一页中被编入.这是我如何定义布局
<?xml version="1.0" encoding="UTF-8"?>
<!--$Id$ -->
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="default" template="/WEB-INF/layouts/default.jspx">
<put-attribute name="header" value="/WEB-INF/views/header.jspx" />
<put-attribute name="submenu" value="/WEB-INF/views/submenu.jspx" />
<put-attribute name="body" value="/WEB-INF/views/body.jspx" />
<put-attribute name="footer" value="/WEB-INF/views/footer.jspx" />
</definition>
<definition name="registration" template="/WEB-INF/layouts/registration.jspx">
<put-attribute name="header" value="/WEB-INF/views/header.jspx" />
<put-attribute name="body" value="/WEB-INF/views/body.jspx" />
</definition>
</tiles-definitions>
Run Code Online (Sandbox Code Playgroud)
视图定义如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition extends="registration" name="register/default">
<put-attribute name="body" value="/WEB-INF/views/register/register.jspx"/>
</definition>
</tiles-definitions>
Run Code Online (Sandbox Code Playgroud)
这是页面代码(registration.jspx)
<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:c="http://java.sun.com/jsp/jstl/core" version="2.0"> …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我想在我的笔记本电脑APP_ENV=local和开发上运行时禁用CSRF APP_ENV=dev.无法通过routes.php或网络中间件来了解如何做到这一点.这是我的routes.php
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
})->middleware('guest');
Route::group(['middleware' => 'auth'], function()
{
Route::resource('battles', 'BattlesController'); //, ['except' => ['index']]);
Route::resource('disputes', 'DisputesController');
Route::resource('messages', 'MessagesController');
});
});
Run Code Online (Sandbox Code Playgroud)
我可以使用一些env文件加载魔法来确保应用程序加载任何一个.local.ev, .dev.env, .test.env, .production.env但我仍然必须找到一种方法来确保web中间件仅包含CSRF时不在本地或开发
Maven 依赖
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.9.0</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我写的测试
@SpringJUnitConfig(classes = {GithubApiService.class, WebClientConfiguration.class})
@EnableAutoConfiguration
public class GithubApiServiceTest {
@Test
public void testGithubResponseJsonToMapConversion(
@Autowired GithubApiService service,
@Value("classpath:github/commit-payload.json") Resource commitPayloadFile) throws IOException {
final String COMMITS_URL = "/repos/Codertocat/Hello-World/commits/sha";
//Stub response from Github Server
String responseJson = new ObjectMapper().writeValueAsString(
new String(Files.readAllBytes(Paths.get(commitPayloadFile.getFile().getAbsolutePath()))));
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse()
.addHeader("Content-Type", "application/json; charset=utf-8")
.setBody(responseJson)
.setResponseCode(OK.value()));
server.start();
// Get mock server's URL
HttpUrl mockGithubUrl = server.url(COMMITS_URL);
//Call API Service
Map<String, Object> result = service.getCommitDetails(mockGithubUrl.toString()).block();
//Expect return …Run Code Online (Sandbox Code Playgroud) StackoverflowError当我们在REST存储库上启用except投影时,我们正面临着.该实体是问题有两个社团,一个@ManyToOne一个Venue是对所有的反应将内嵌包括实体,并且@OneToMany与Trainee实体,我们总是要隐藏.实体(相关)片段
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Workshop implements Serializable {
private static final long serialVersionUID = -5516160437873476233L;
private Long id;
// omitted properties
private Venue venue;
private Set<Trainee> trainees;
@Id
@GeneratedValue
public Long getId() {
return id;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinTable(name = "workshop_venue", joinColumns = { @JoinColumn(name = "workshop_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "venue_id", referencedColumnName = "id") })
public Venue getVenue() {
return venue;
}
@OneToMany …Run Code Online (Sandbox Code Playgroud) 我正在使用simple-formgem 中的集合渲染一组字符串,我已经完成了这个答案,但是那里的解决方案效果不佳。
这是标签
<%= f.input :training_modes, collection: get_training_modes, include_blank: false, input_html: { multiple: true } %>
Run Code Online (Sandbox Code Playgroud)
但是当我通过这个选择保存时,我得到了这样的数组
["", "Instructor Led Training", "Webex"]
Run Code Online (Sandbox Code Playgroud) 我收到错误
Error: Call to undefined method Illuminate\Events\Dispatcher::assertDispatched()
为了测试
<?php
namespace Tests\Unit;
use Tests\TestCase;
use App\Entities\Requester;
use App\Observers\RequesterObserver;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
class RequesterObserverTest extends TestCase {
use RefreshDatabase;
public function setUp()
{
parent::setUp();
Mail::fake();
}
public function testRequesterCreationTriggersObserver(){
$expected = factory(Requester::class)->create();
//assert the creation event observer is fired
Event::assertDispatched(RequesterObserver::class, function($event) use ($expected){
return $event->requester->email_id === $expected->email_id;
});
}
}
Run Code Online (Sandbox Code Playgroud)
该方法已按照 Laravel 5.5 文档中的说明使用,当我在调试模式下运行时,我确实看到了正在触发的实际事件,但是测试在这一行给出了错误
Event::assertDispatched(RequesterObserver::class, function($event) use ($expected)
Run Code Online (Sandbox Code Playgroud) 我似乎对如何在请求规范测试中发出发布请求以测试url不太了解,这是测试代码
RSpec.describe "Certifications", type: :request do
describe "denies public access" do
it "for new certification form" do
get new_certification_path
expect(response).to redirect_to new_user_session_path
end
it "for creating certification" do
certification_attributes = FactoryGirl.attributes_for :certification
expect {
post "/certifications", { certification: certification_attributes }
}.to_not change(Certification, :count)
expect(response).to redirect_to new_user_session_path
end
end
end
Run Code Online (Sandbox Code Playgroud)
这给出了错误
1) Certifications denies public access for creating certification
Failure/Error: post "/certifications", { certification: certification_attributes }
ArgumentError:
unknown keyword: certification
Run Code Online (Sandbox Code Playgroud)
我已经尝试过:certifications => certification_attributes,基本上无法理解如何传递参数。
被测控制器仅向该帖子添加相关方法。
class CertificationsController < ApplicationController
skip_before_action …Run Code Online (Sandbox Code Playgroud) spring ×5
java ×3
laravel ×2
laravel-5 ×2
php ×2
spring-boot ×2
spring-data ×2
spring-mvc ×2
gradle ×1
heroku ×1
http-post ×1
javascript ×1
jspx ×1
laravel-5.2 ×1
okhttp ×1
puma ×1
recaptcha ×1
rspec ×1
rspec-rails ×1
ruby ×1
simple-form ×1
tar ×1
thymeleaf ×1
tiles ×1