小编kri*_*aex的帖子

ZipInputStream(InputStream,Charset)错误地解码ZipEntry文件名

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)

java character-encoding zipinputstream

5
推荐指数
1
解决办法
1万
查看次数

AspectJ:一个方面内多个建议的执行顺序(优先级)

类使用编译时编织.

想象一下,我有方面类:

@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)

java aop aspectj

5
推荐指数
2
解决办法
7017
查看次数

使用 Spring @Configuration 和 MethodInterceptor 拦截带注释的方法

我需要使用 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 注释来指定拦截器何时应该拦截某些东西,但现在已经不存在了。

谁能帮我?

非常感谢!

卢卡斯

spring-aop aopalliance

5
推荐指数
1
解决办法
4121
查看次数

具有@Scheduled Spring批注的方法的切入点

我想为带有方法注释的方法设置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注解的方法?

java spring aspectj spring-scheduled

5
推荐指数
1
解决办法
2128
查看次数

Spring AOP:排除避免切入点的最终类和枚举

我正在尝试使用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)

aop spring aspectj spring-aop

5
推荐指数
1
解决办法
3661
查看次数

方面没有被执行

我们在函数上有一个注释如下

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)

java spring aspectj spring-aop

5
推荐指数
1
解决办法
225
查看次数

@RetryTransaction:如何在发现死锁时使其工作

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)

java spring transactions aspectj

5
推荐指数
1
解决办法
728
查看次数

由于无法加载主类错误,无法运行 JAR 文件

我使用 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 …

java program-entry-point jar build manifest

5
推荐指数
1
解决办法
1815
查看次数

切入点不适用于Spring AOP

为了使用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)

java logging aop spring spring-aop

4
推荐指数
1
解决办法
7358
查看次数

IntelliJ ajc:如何从aspectj-maven-plugin 工作中排除?

我在 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 aspectj intellij-idea maven aspectj-maven-plugin

4
推荐指数
1
解决办法
569
查看次数