我需要在项目的源代码上运行注释处理器.注释处理器不应该成为项目的传递依赖项,因为它只需要注释处理而不需要其他内容.
这是我用于此的完整(非工作)测试pom:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test annotations</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate-jpamodelgen.version>1.2.0.Final</hibernate-jpamodelgen.version>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<annotationProcessors>
<annotationProcessor>
org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</annotationProcessor>
</annotationProcessors>
<debug>true</debug>
<optimize>true</optimize>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<AaddGeneratedAnnotation>true</AaddGeneratedAnnotation>
<Adebug>true</Adebug>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate-jpamodelgen.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
我org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
在测试的插件配置中明确定义为注释处理器,我知道它不应该是必需的.
我遇到的问题是hibernate-jpamodelgen
依赖项没有添加到编译器类路径中,因此找不到注释处理器并且构建失败.
根据这个答案,我尝试将依赖项添加为构建扩展(不确定我理解那些应该是什么!),如下所示:
<extensions>
<extension>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate-jpamodelgen.version}</version>
</extension>
</extensions>
Run Code Online (Sandbox Code Playgroud)
这也不会添加hibernate-jpamodelgen
到编译器类路径中.
到目前为止,我发现唯一可行的方法是在该<dependencies>
部分中将依赖项添加到项目中.这有一个令人遗憾的副作用,hibernate-jpamodelgen …
我正在为一个项目尝试Java 7并从这种注释处理器(Bindgen和Hibernate JPA modelgen)获得警告:
warning: Supported source version 'RELEASE_6' from annotation processor 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' less than -source '1.7'
Run Code Online (Sandbox Code Playgroud)
这是由@SupportedSourceVersion(SourceVersion.RELEASE_6)
注释处理器类上的注释引起的.由于它们是使用Java 6编译的,因此SourceVersion
可用的最高值是RELEASE_6
.Java 7版本SourceVersion
介绍RELEASE_7
.
我的问题:注释处理器如何处理前向兼容性?是否必须有单独的jdk6和jdk7二进制版本?我在这里不理解其他什么吗?
我只发现了有关此问题的以下信息:
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
Run Code Online (Sandbox Code Playgroud)
评论员建议支持最新源版本的Oracle博客
我想重新使用来自不同*Mapper.xml文件的特定文件,这些文件都以某种方式读取相同的对象.
我有一个名为Project的数据库表,我创建了以下resultMap:
<resultMap id="ProjectMap" type="com.model.Project">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="client_prj_no" jdbcType="VARCHAR" property="clientPrjNo" />
<result column="notes" jdbcType="VARCHAR" property="notes" />
<result column="start_date" jdbcType="TIMESTAMP" property="startDate" />
...
<resultMap>
Run Code Online (Sandbox Code Playgroud)
它在ProjectMapper.xml中工作得很好,但是,现在我想创建一个ClientWithProjectsMapper.xml,我想要SELECT*FROM CLIENT,PROJECT,其中PROJECT.CLIENT_ID = CLIENT.ID并且Client对象返回一个List对象.换句话说,我想用一个SQL获取ClientWithProjects.
在我的映射中,我想重用我在ProjectMapper.xml中定义的ProjectMap(没有复制/粘贴),但我不知道如何实现这一点.
我可以将ProjectMap分解为一个单独的文件,但我没有在MyBatis中找到#include其他文件的任何工具.
关于如何做到这一点的任何想法?(我正在使用Maven,是否有任何插件可以过滤寻找#include等文件,并将文件内容直接包含在正在处理的文件中?).
谢谢.
-AP_
我正在将我的Laravel 4.2应用程序迁移到5.1(从5.0开始),并且我的控制台命令单元测试很麻烦.我有工匠命令,我需要测试生成的控制台输出,正确的问题/响应处理以及与其他服务的交互(使用模拟).尽管如此,Laravel文档在测试控制台命令方面仍然是无声的.
我终于找到了一种创建这些测试的方法,但感觉就像是对那些setLaravel
和setApplication
调用的黑客攻击.
有一个更好的方法吗?我希望我可以将我的模拟实例添加到Laravel IoC容器中,并让它创建命令以测试所有正确设置的内容.我担心我的单元测试会在较新的Laravel版本中轻松破解.
这是我的单元测试:
使用陈述:
use Mockery as m;
use App\Console\Commands\AddClientCommand;
use Symfony\Component\Console\Tester\CommandTester;
Run Code Online (Sandbox Code Playgroud)
建立
public function setUp() {
parent::setUp();
$this->store = m::mock('App\Services\Store');
$this->command = new AddClientCommand($this->store);
// Taken from laravel/framework artisan command unit tests
// (e.g. tests/Database/DatabaseMigrationRollbackCommandTest.php)
$this->command->setLaravel($this->app->make('Illuminate\Contracts\Foundation\Application'));
// Required to provide input to command questions (provides command->getHelper())
// Taken from ??? when I first built my command tests in Laravel 4.2
$this->command->setApplication($this->app->make('Symfony\Component\Console\Application'));
}
Run Code Online (Sandbox Code Playgroud)
输入作为命令参数提供.检查控制台输出
public function testReadCommandOutput() {
$commandTester = new CommandTester($this->command);
$result …
Run Code Online (Sandbox Code Playgroud) 使用以下html结构:
<div>
<form><span><input></span></form>
</div>
<p>
Run Code Online (Sandbox Code Playgroud)
和以下jquery代码:
$('form').on("focus", function(event) {
$("p").append("focus no delegation<br>");
})
Run Code Online (Sandbox Code Playgroud)
为什么焦点事件没有到达我的事件处理程序?使用选择器参数绑定事件可以正常工作:
$('form').on("focus", "input", function(event) {
$("p").append("focus delegation<br>");
})
Run Code Online (Sandbox Code Playgroud)
活动下一个片段的作用,所以焦点事件实际上泡沫......
$('form').on("focus", "span", function(event) {
$("p").append("focus delegation<br>");
})
Run Code Online (Sandbox Code Playgroud)
两种形式都适用于点击和更改事件:
$('form').on("click", function(event) {
$("p").append("click no delegation<br>");
})
$('form').on("click", "input", function(event) {
$("p").append("click delegation<br>");
})
Run Code Online (Sandbox Code Playgroud)
我发现关于焦点事件冒泡的唯一注意事项是相对于我不使用的旧jQuery版本.在这里看到它
这很令人困惑......根据jQuery的焦点文档:
焦点事件不会在Internet Explorer中冒泡.因此,依赖于焦点事件的事件委派的脚本将无法跨浏览器一致地工作.但是,从版本1.4.2开始,jQuery通过将焦点映射到其事件委托方法.live()和.delegate()中的focusin事件来解决此限制.
根据jQuery的焦点文档:
当focusin或其中的任何元素获得焦点时,focusin事件将被发送到元素.这与焦点事件的不同之处在于它支持在父元素上检测焦点事件(换句话说,它支持事件冒泡).
对我来说为时已晚还是与另一方相矛盾?
我已忽略了该paste
事件。我注意到,由于阻止了事件的默认行为,因此当前无法使用Ctrl + Z撤消“粘贴”。
$(this).on('paste', function (evt) {
// Get the pasted data via the Clipboard API.
// evt.originalEvent must be used because this is jQuery, not pure JS.
// /sf/answers/2088211891/
var clipboardData = evt.originalEvent.clipboardData || window.clipboardData;
var pastedData = clipboardData.getData('text/plain');
// Trim the data and set the value.
$(this).val($.trim(pastedData));
// Prevent the data from actually being pasted.
evt.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以覆盖撤消功能,或者可以做其他不同的操作以使Ctrl + Z起作用?
在带注释的 MVC 控制器中进行以下验证设置:
@RestController
@RequestMapping("/users")
@Validated // <-- without this, the @Size annotation in setPassword() has no effect
public class UserController {
@PutMapping("/{id}/password")
public void setPassword(@PathVariable long id, @RequestBody @Size(min = 8) String password) {
/* ... */
}
@PutMapping("/{id}/other")
public void setOther(@PathVariable long id, @RequestBody @Valid MyFormObject form) {
/* ... */
}
}
Run Code Online (Sandbox Code Playgroud)
@Validated
方法参数需要控制器上的 ,因为它不是一个“复杂”对象。相比之下,方法@Valid
上的注释setOther
无需注释即可工作@Validated
。
为什么@Validated
需要?为什么不默认启用它?使用它需要付费吗?
请注意,Spring 中的 @Valid 和 @Validated 之间的差异是相关的(我在问这个之前读过它),但它没有解决我的问题中的原因。
我想在从Java Web应用程序(Wicket)调用它们的方法时将身份验证信息传递给EJB无状态会话bean.该信息由用户ID和身份验证类型(记住cookie或用户/密码)组成,并存储在http会话中.一个明显的解决方案是将此作为参数添加到所有EJB方法,但这很麻烦,我希望存在另一种解决方案.
EJB bean的JNDI查找是通过Web层中的javax.naming.InitialContext#lookup(String)完成的.
是否有一种可移植的方法可以将身份验证信息添加到调用上下文中,以便bean可以使用它?我需要此过程可用于EJB层(对于最终的Web服务端点)和Web层中的调用者.
我正在使用Java EE 6.不使用CDI,我宁愿避免实现它.
身份验证由Web层处理,无状态bean验证记住cookie和用户/密码组合.当访问者首次访问该站点时,将尝试使用remember cookie进行身份验证.最终需要时,系统会要求用户使用用户名和密码登录.如上所述,身份验证状态存储在http会话中.我不使用基于领域的Java EE安全模型,因为我无法弄清楚如何正确集成此身份验证流程.
授权方案基于动态角色,类似于Facebook根据2个用户和某些偏好之间的链接确定授权的方式.某些操作还会考虑身份验证类型.例如,修改帐户设置需要用户/密码,而cookie是不够的.根据我的理解,Java EE标准组和角色不适合这个要求.
EJB3&JAAS主题/主体如何从servlet容器传播到EJB层?
我希望我的问题很清楚.如果需要更多信息,我很乐意提供.
固定链接.添加关于CDI的说明.
Freemarker(默认情况下)使用区域设置来构建它在加载和包含模板时查找的文件名.例如,tos.ftl
使用en_US
区域设置加载(模板)将查找:
当页面在不同语言之间完全不同时,这对于翻译整个页面非常有用.例如,"服务条款"页面可能主要是静态的,因此不同的语言将具有完全不同的内容.在这种情况下,将整个内容外部化到从消息包加载的消息是一件麻烦事.
我现在正在学习Thymeleaf,无法找到有关类似功能的任何信息.我知道Thymeleaf使用本地化的消息包来填充th:text
元素,但是它可以加载模板文件的本地化版本吗?
注意:我正在使用Spring Boot
Eclipse和Java EE代码中的调试会话很痛苦,我希望有人比我的方法更好.
这是两个EJB无状态bean方法之间的典型调用堆栈(使用TomEE 1.0):
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) line: 597
ReflectionInvocationContext$BeanInvocation(ReflectionInvocationContext$Invocation).invoke() line: 181
ReflectionInvocationContext.proceed() line: 163
StatsInterceptor.record(InvocationContext, Method) line: 176
StatsInterceptor.invoke(InvocationContext) line: 95
GeneratedMethodAccessor35.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) line: 597
ReflectionInvocationContext$InterceptorInvocation(ReflectionInvocationContext$Invocation).invoke() line: 181
ReflectionInvocationContext.proceed() line: 163
CdiInterceptor.invoke(InvocationContext) line: 129
CdiInterceptor.access$000(CdiInterceptor, InvocationContext) line: 45
CdiInterceptor$1.call() line: 66
CdiInterceptor.aroundInvoke(InvocationContext) line: 72
GeneratedMethodAccessor34.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) …
Run Code Online (Sandbox Code Playgroud) java ×4
java-ee ×2
javascript ×2
jquery ×2
spring ×2
spring-boot ×2
spring-mvc ×2
annotations ×1
debugging ×1
eclipse ×1
ejb-3.0 ×1
freemarker ×1
java-6 ×1
java-7 ×1
java-ee-6 ×1
jpa-2.0 ×1
laravel ×1
laravel-5 ×1
laravel-5.1 ×1
mappers ×1
maven ×1
maven-3 ×1
mybatis ×1
paste ×1
php ×1
refactoring ×1
resultset ×1
security ×1
thymeleaf ×1
undo ×1
unit-testing ×1
validation ×1