Maven的默认合规级别是1.5,每次我在Eclipse中更新maven项目时,它都会将合规级别从1.6恢复到1.5,这对我来说真的很烦人.
我知道我可以在POM文件中将目标设置为1.6,但问题是我不能在父POM中设置它并期望子进程继承它.所以我必须为每个Maven模块做这件事.如何在我的Maven项目或整个eclipse中设置一次"生命周期"而不修改每个Maven模块!?
我正在使用Spring的@DataJpaTest进行测试,然后将H2用作内存数据库,如此处所述.我也在使用Flyway进行制作.但是一旦测试开始,FLyway就会启动并读取SQL文件.我如何排除FlywayAutoConfiguration,并按照Spring文档中的描述保留其余内容,以便让Hibernate为我创建H2中的表?
@RunWith(SpringRunner.class)
@DataJpaTest
public class MyRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private MyRepository triggerRepository;
}
Run Code Online (Sandbox Code Playgroud) 我刚刚下载了OEPE(Kepler)并安装了m2e和m2e-wtp连接器.我发现在这条路径下:首选项 - > Maven->生命周期映射 - >打开工作区生命周期映射数据有一个预先配置的xml文件,该文件说maven应该忽略AspectJ的编译目标,我认为这就是为什么AspectJ运行时库是未添加到项目中,因此eclipse不会将项目识别为AspectJ项目.
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<versionRange>1.6</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
Run Code Online (Sandbox Code Playgroud)
我在xml文件中注释掉了这些行并再次重新加载.现在IDE不会忽略生命周期中的AspectJ插件标记,但是pom文件抱怨它无法识别执行标记.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
使用indigo,m2e-wtp能够识别<execution>aspectj插件的标签,并能够自动将AspectJ运行时库添加到项目中,尽管在开普勒中并非如此.(我认为m2e-wtp的工作是将一个AspectJ项目从pom中取出但不太确定.)
顺便说一句.我怎么能像Indigo那样让事情发挥作用?我知道我可以右键单击项目并将其转换为Aspect项目以解决问题,但我希望IDE和插件从pom文件中实现该项目需要AspectJ jar.任何的想法?
我写了一个ParamConverterProvider和一个ParamConverter,以便让JAX-RS(Jersey)在HeaderParam中实例化一个枚举.转换器看起来像这样
@Provider
public class MyEnumParamConverterProvider implements ParamConverterProvider {
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (rawType.equals(MyEnum.class)) {
return (ParamConverter<T>) new MyEnumParamConverter();
}
return null;
}
private static class MyEnumParamConverter implements ParamConverter<MyEnum> {
@Override
public MyEnum fromString(String enum) {
return MyEnum.of(enum);
}
@Override
public String toString(MyEnum enum) {
return enum.toString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当没有发送Header时没有调用fromString方法,因为在方法类SingleValueExtractor中的Jersey代码org.glassfish.jersey.server.internal.inject.SingleValueExtractor.extract(MultivaluedMap<String, String>)上,第82行有一个代码检查参数值是否为null,如果它是!= null则fromString方法叫做.
public T extract(MultivaluedMap<String, String> parameters) {
String v = parameters.getFirst(getName());
if (v != null) {
try {
return fromString(v); …Run Code Online (Sandbox Code Playgroud) 我有一个DAO类,可以javax.persistence.PersistenceException将它们包装起来并作为检查后的异常重新抛出。此方法标记为@org.springframework.transaction.annotation.Transactional。
如果我在DAO中遇到异常,例如违反约束,它将包装在我的自定义异常中,但是spring会覆盖我的异常
[tp1415357209-22] o.s.t.i.TransactionInterceptor : Application exception overridden by commit exception
Run Code Online (Sandbox Code Playgroud)
并抛出自己的 org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
通过记录并重新抛出自己的异常来“吞噬”我的异常。如何防止spring这样做?
聚苯乙烯
@Transactional(noRollbackFor = { MyCustomException.class})
Run Code Online (Sandbox Code Playgroud)
不起作用。当然,我确实希望将事务设置为回滚,但是我不希望我的异常被春天吞没。