小编Sou*_*aik的帖子

Java编译器错误解惑:"内部类不能有静态声明" - 除了简单类型

编码时,我遇到了一个奇怪的Java编译器行为.

编译类(下面的源代码)时,编译器inner classes cannot have static declarations会对NULL类变量发出错误(" ").这是预期的!

但是,ZERO类变量不会生成错误.这个我不明白!

为什么这种差异似乎允许内部类中的简单类型而不是对象的静态声明.

(javac -version:1.6.0_24)

public class Outer {
    public static final Runnable HELLO = new Runnable() {
        // No compiler error
        public static final int ZERO = 0;

        // Causes compiler error: "inner classes cannot have static declarations"
        public static final Object NULL = null;

        @Override
        public void run() {
            System.out.println("Hello " + ZERO + NULL);
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

java compiler-construction compiler-errors

9
推荐指数
1
解决办法
7160
查看次数

在@Scheduled方法中调用Spring @Async方法

我正在使用Spring启动@EnableScheduling@EnableAsync.

我有一个注释的方法@Scheduled.我有几个方法,用注释@Async.

现在我在@Async方法中调用这些方法,@Scheduled并在异步方法中打印出当前线程的名称.我看到的是它们都有相同的线程名称,实际上它是运行该@Scheduled方法的线程.

我没有看到异步方法执行.这有什么不对?

这是我的应用程序启动类

@SpringBootApplication
@EnableScheduling
@EnableAsync
public class ApplicationBoot {

    public static void main(String[] args) {
        SpringApplication.run(ApplicationBoot.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的调度程序类

@Component
public class TaskScheduler {
    private static final Logger logger = Logger.getLogger(TaskScheduler.class);

    @Scheduled(fixedDelay = 10000)
    public void ScheduledMethod() {
        methodOne();
        methodTwo();
        methodThree();
    }

    @Async
    private void methodOne() {
        logger.info("Method one called  by Thread : " + Thread.currentThread().getName() + "  at " + new …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot spring-async

7
推荐指数
2
解决办法
3491
查看次数

如何在运行时更改假网址?

@FeignClient(name ="test",url ="http:// xxxx")

如何在运行时更改feign url(url ="http:// xxxx")?因为网址只能在运行时确定.

spring-cloud spring-cloud-feign

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

Wicket pageparameter

我正在尝试使用Wicket中的键String和值来添加和获取.List<object>PageParameters

虽然我用钥匙取得价值,但我得到了 classcastException:String cant be converted into list.

我使用的是这样的东西:

List<Example> list = (List<Example>)params.get("ExampleList");
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

java wicket

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

Swagger中重载的控制器方法

我有一个Spring REST应用程序.我使用Swagger进行API文档编制.

我有什么我的REST控制器,方法@RequestMapping.我有两个重载方法,它们在参数方面有所不同.但Swagger UI只显示一个.

是我的方法是错误的(重载控制器方法)还是Swagger中的错误?

java spring swagger swagger-ui swagger-2.0

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

在 Spring 中缓存带有数组参数的方法

我有一个具有多种方法的服务,并尝试使用 Spring@Cacheable注释来缓存它们。一切正常,除非我发现带有数组作为方法参数的方法没有被缓存。考虑到数组可以保存不同的值,这有点有意义,但我仍然认为这是可能的。

缓存了以下方法:

@Cacheable("myCache")
public Collection<Building> findBuildingByCode(String buildingCode) {...}

@Cacheable("myCache")
public Collection<Building> getBuildings() {...}
Run Code Online (Sandbox Code Playgroud)

但是,如果我将findBuildingByCode方法更改为以下任一方法,则不会缓存它:

@Cacheable("myCache") 
public Collection<Building> findBuildingByCode(String[] buildingCode) {...}

@Cacheable("myCache")
public Collection<Building> findBuildingByCode(String... buildingCode) {...}
Run Code Online (Sandbox Code Playgroud)

这是相关的Spring xml配置:

<!-- Cache beans -->
<cache:annotation-driven/>

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
    p:cache-manager-ref="ehcache" />

<!-- EhCache library setup -->
<bean id="ehcache"
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
Run Code Online (Sandbox Code Playgroud)

ehcache配置:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">

<diskStore path="java.io.tmpdir/ehcache" />

<!-- Default settings -->
<defaultCache eternal="false" maxElementsInMemory="1"
    overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
    timeToLiveSeconds="100" memoryStoreEvictionPolicy="LRU" />

<!-- …
Run Code Online (Sandbox Code Playgroud)

java spring ehcache spring-annotations

3
推荐指数
1
解决办法
8288
查看次数

Spring Boot中如何配置Redis缓存?

如何使用 Spring Boot 配置 Redis 缓存。据我所知,这只是application.properties文件中的一些更改,但不知道具体是什么。

java spring caching redis spring-boot

2
推荐指数
1
解决办法
9933
查看次数

如何在Wicket Session类中自动装配Spring bean?

我有一个Wicket Session类,如下所示

public class IASession extends AuthenticatedWebSession {
    private static final long serialVersionUID = 3529263965780210677L;

    @SpringBean
    private UserService userService;

    public IASession(Request request) {
        super(request);
    }

    @Override
    public boolean authenticate(String username, String password) {

        // Get the user
        UserDetailsDTO user = userService.findByEmail(username);

        if(null != user && user.getPassword().equals(password))
            return true;
        else
            return false;
    }

    @Override
    public Roles getRoles() {
        Roles roles = new Roles();
        roles.add("SIGNED_IN");
        return roles;
    }
}
Run Code Online (Sandbox Code Playgroud)

在这个课程中,我试图使用wicket-spring注释来自动装配Spring服务@SpringBean.但是当我尝试登录时,它给了我错误.

Last cause: null
WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted …
Run Code Online (Sandbox Code Playgroud)

java spring wicket

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