Java 7应该通过解压缩包含UTF-8以外字符集的zip存档来解决一个老问题.这可以通过构造函数来实现ZipInputStream(InputStream, Charset).到现在为止还挺好.在明确设置ISO-8859-1字符集时,我可以解压缩包含文件名的zip存档,其中包含变音符号.
但问题是:当使用流迭代流时ZipInputStream.getNextEntry(),条目的名称中包含错误的特殊字符.在我的情况下,变音符号"ü"被"?"取代 性格,这显然是错误的.有人知道如何解决这个问题吗?显然ZipEntry忽略了Charset它的基础ZipInputStream.它看起来像是另一个与zip相关的JDK错误,但我也可能做错了.
...
zipStream = new ZipInputStream(
new BufferedInputStream(new FileInputStream(archiveFile), BUFFER_SIZE),
Charset.forName("ISO-8859-1")
);
while ((zipEntry = zipStream.getNextEntry()) != null) {
// wrong name here, something like "M?nchen" instead of "München"
System.out.println(zipEntry.getName());
...
}
Run Code Online (Sandbox Code Playgroud) 类使用编译时编织.
想象一下,我有方面类:
@Aspect
public class SecurityInterceptor {
@Pointcut("within(@org.springframework.stereotype.Controller *)")
public void beanAnnotatedWithController() {}
@Pointcut("execution(public * *(..)) && args(*,httpReq)")
public void publicMethods(HttpServletRequest httpReq) {}
@Pointcut("beanAnnotatedWithController() && publicMethods(httpReq)")
public void controllerMethods(HttpServletRequest httpReq) {}
@Pointcut("execution(public * *(..)) && args(httpReq)")
public void publicMethodsRequestOnly(HttpServletRequest httpReq) {}
@Pointcut("beanAnnotatedWithController() && publicMethodsRequestOnly(httpReq)")
public void controllerMethodsOneArg(HttpServletRequest httpReq) {}
@Around(value = "controllerMethods(httpReq)")
public Object populateSecurityContext(final ProceedingJoinPoint joinPoint, HttpServletRequest httpReq) throws Throwable {
return popSecContext(joinPoint, httpReq);
}
@Around(value = "controllerMethodsOneArg(httpReq)")
public Object populateSecurityContextOneArg(final ProceedingJoinPoint joinPoint, HttpServletRequest httpReq) throws Throwable {
return …Run Code Online (Sandbox Code Playgroud) 我需要使用 spring-aop 拦截带注释的方法。我已经有了拦截器,它实现了 AOP 联盟的 MethodInterceptor。
这是代码:
@Configuration
public class MyConfiguration {
// ...
@Bean
public MyInterceptor myInterceptor() {
return new MyInterceptor();
}
}
Run Code Online (Sandbox Code Playgroud)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
// ...
}
Run Code Online (Sandbox Code Playgroud)
public class MyInterceptor implements MethodInterceptor {
// ...
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
//does some stuff
}
}
Run Code Online (Sandbox Code Playgroud)
从我过去读到的内容来看,我可以使用 @SpringAdvice 注释来指定拦截器何时应该拦截某些东西,但现在已经不存在了。
谁能帮我?
非常感谢!
卢卡斯
我想为带有方法注释的方法设置AspectJ切入点@Scheduled。尝试了不同的方法,但没有任何效果。
1.)
@Pointcut("execution(@org.springframework.scheduling.annotation.Scheduled * * (..))")
public void scheduledJobs() {}
@Around("scheduledJobs()")
public Object profileScheduledJobs(ProceedingJoinPoint joinPoint) throws Throwable {
LOG.info("testing")
}
Run Code Online (Sandbox Code Playgroud)
2.)
@Pointcut("within(@org.springframework.scheduling.annotation.Scheduled *)")
public void scheduledJobs() {}
@Pointcut("execution(public * *(..))")
public void publicMethod() {}
@Around("scheduledJobs() && publicMethod()")
public Object profileScheduledJobs(ProceedingJoinPoint joinPoint) throws Throwable {
LOG.info("testing")
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以提出任何其他方式都around/ before上建议@Scheduled注解的方法?
我正在尝试使用Spring AOP实现Logging.我已定义了
@Pointcut("execution(* com.mycom..*(..))")
private void framework() {}
@Around("framework()")
public Object aroundAdviceFramework(ProceedingJoinPoint jp) throws Throwable {
if (logger.isDebugEnabled())
logger.debug("DEBUG:: {} {} Enter", jp.getTarget().getClass().getName(), jp.getSignature().getName());
Object returnVal = jp.proceed(jp.getArgs());
if (logger.isDebugEnabled())
logger.debug("DEBUG:: {} {} Out", jp.getTarget().getClass().getName(), jp.getSignature().getName());
logger.info("INFO:: " + jp.getTarget().getClass().getName() + " " + jp.getSignature().getName() + " Finished:");
return returnVal;
}
Run Code Online (Sandbox Code Playgroud)
mycom包及其子包下有很多类.有些课程是enum和final class.因此,我得到了
nested exception is org.springframework.aop.framework.AopConfigException:
Could not generate CGLIB subclass of class [class com.mycom.util.BancsServiceProvider]: Common causes of this problem include using a final class or a non-visible class; …Run Code Online (Sandbox Code Playgroud) 我们在函数上有一个注释如下
public class AnInterfaceImpl implements AnInterface {
@FairThreadUsageByEntity(entityName = "XYXYXYX",
numberOfThreads = 1)
public Report getReport(final String One, final String Two) {
//implementation.
}
}
public interface AnInterface {
String BEAN_NAME = "AnInterface"; //used for injection in spring.
Report getReport(final String One, final String two);
}
Run Code Online (Sandbox Code Playgroud)
弹簧配置:
<aop:aspectj-autoproxy />
<bean class="com.amazon.utils.fairthreadusage.aspect.FairThreadUsageByEntityAdvice" />
Run Code Online (Sandbox Code Playgroud)
注释作为一个方面实现.基本功能是限制特定类型功能使用的线程数,让我们说下载.以下是注释的代码FairThreadUsageByEntity:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface FairThreadUsageByEntity {
public String entityName();
public int numberOfThreads();
}
@Aspect
public class FairThreadUsageByEntityAdvice extends FairThreadUsageBase {
@Around("@annotation(fairUsage)")
public Object fairThreadUsageByEntity(final ProceedingJoinPoint …Run Code Online (Sandbox Code Playgroud) Concurent Transaction使我的Sql语句失败.我正在尝试使用[这] dellroad-stuff 1.但它似乎被忽略了.我正在使用spring 3和hibernate 4.
错误 :
15:32:11,331 WARN SqlExceptionHelper:145 - SQL Error: 1213, SQLState: 40001
15:32:11,331 ERROR SqlExceptionHelper:147 - Deadlock found when trying to get lock; try restarting transaction
15:32:11,334 INFO AbstractBatchImpl:195 - HHH000010: On release of batch it still contained JDBC statements
Run Code Online (Sandbox Code Playgroud)
如果失败则重写事务的annoted函数:
@Override
@RetryTransaction
@Transactional
public void save(AnalyseResult analyseResult) {
final int attempt = RetryTransactionAspect.aspectOf().getAttemptNumber();
System.out.println("#############");
System.out.println("Retry Transact : "+attempt);
System.out.println("#############");
analyseResultDao.save(analyseResult);
}
Run Code Online (Sandbox Code Playgroud)
Beans.xml
<!-- An @AspectJ aspect will be interpreted as an aspect by …Run Code Online (Sandbox Code Playgroud) 我使用 Gradle 构建框架构建了项目并生成了 JAR 文件。但是,输出 jar 文件无法从主类(miner.Tracker。
正如我提到的,使用选项运行-jar失败。
$ java -jar Backtracker.jar
Error: Could not find or load main class miner.Tracker
Run Code Online (Sandbox Code Playgroud)
我也尝试直接使用选项运行该类-cp,但失败了。
$ java -cp Backtracker.jar miner.Tracker
Error: Could not find or load main class miner.Tracker
Run Code Online (Sandbox Code Playgroud)
最后,我解压缩了 jar 文件并从内部调用该类。这次,它成功找到并运行了具有 main 方法的类。
$ java -cp Backtracker.jar miner.Tracker
Error: Could not find or load main class miner.Tracker
Run Code Online (Sandbox Code Playgroud)
这是文件的内容META-INF/MANIFEST.MF。
Manifest-Version: 1.0
Implementation-Title: BackTracker
Implementation-Version: 1.9.xx
Specification-Title: release
Specification-Version: 1.9.xx
Main-Class: miner.Tracker
Run Code Online (Sandbox Code Playgroud)
我从 Oracle Java 1.8 …
为了使用Spring AOP实现Logging,我遵循了这些简单的步骤.但它似乎无法正常工作.任何帮助都会有用
1)创建了MyLoggingAspect类
import org.aspectj.lang.ProceedingJoinPoint;
public class MyLoggingAspect
{
public MyLoggingAspect() {
super();
System.out.println("Instantiated MyLoggingAspect");
}
public Object log(ProceedingJoinPoint call) throws Throwable
{
System.out.println("from logging aspect: entering method [" + call.toShortString()
+"] with param:"+call.getArgs()[0] );
Object point = call.proceed();
System.out.println("from logging aspect: exiting method [" + call.toShortString()
+ "with return as:" +point);
return point;
}
Run Code Online (Sandbox Code Playgroud)
}
2)创建了一个我想要记录的类(TixServiceImpl)
public class TixServiceImpl implements TixService{
@Override
public void calculateSomething() {
String s = "did some calculation..";
System.out.println(s);
}
@Override …Run Code Online (Sandbox Code Playgroud) 我在 IntelliJ 中使用了 ajc 编译器,以及 aspectj-maven-plugin,我在其中声明了以下排除项:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/EmployeeAccessAspect.java</exclude>
</excludes>
<complianceLevel>1.8</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我使用 编译时mvn compile,一切都很好,并且EmployeeAccessAspect方面被正确忽略。
但是,如果我Make是 IntelliJ 中的项目,它只会编织它找到的所有方面(并完全忽略 maven 排除项)。
我总是可以破解 ajc 编译器选项或方面路径来实现我想要的,但是如果我出于某种原因必须排除一个方面,它会让我改变两个地方。
有什么办法可以让maven插件和ajc编译同步吗?我正在使用 IntelliJ 15。
java ×8
aspectj ×6
spring ×5
spring-aop ×4
aop ×3
aopalliance ×1
build ×1
jar ×1
logging ×1
manifest ×1
maven ×1
transactions ×1