我正在将我们的代码迁移到Spring 3.2版本(从3.1.3开始),我遇到了Spring Cache Abstraction的问题.
我们使用EhCache实现,CacheManager其配置非常简单:
<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache" />
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="classpath:ehcache.xml" />
Run Code Online (Sandbox Code Playgroud)
我的问题是我缺少EhCacheCacheManager类和相应的工厂bean spring-context jar.我想他们将实现转移到其他模块,但我找不到确切的位置.
好吧,我知道很难理解线程是如何工作的,但是直到有人帮助我理解我会相信它是一个bug :)
在我的Main类及其main()方法中,我有:
public static void main(String args[]){
StoneBucket stoneBucket = new StoneBucket();
StonePutter spRunnable = new StonePutter(stoneBucket);
StoneThrower stRunnable = new StoneThrower(stoneBucket);
StoneThrower stRunnable2 = new StoneThrower(stoneBucket);
//Create the Threads that will take the Runnables as arguments
Thread puttingThread = new Thread(spRunnable);
Thread throwingThread = new Thread(stRunnable);
Thread throwingThread2 = new Thread(stRunnable);
puttingThread.setName("Putter");
throwingThread.setName("Thrower 1");
throwingThread2.setName("Thrower 2");
[...]
Run Code Online (Sandbox Code Playgroud)
然后在我的StoneThrower课程中
public class StoneThrower implements Runnable{
private StoneBucket sb;
private String name;
public StoneThrower(StoneBucket _sb){
this.sb = _sb;
}
public void …Run Code Online (Sandbox Code Playgroud) 我正在使用Eclipse调试器,无法检查/监视字段值或field.method()调用的结果.我在Juno和现在的Indigo都遇到过这个问题.起初我可以通过消除我的.metadata和重建来解决这个问题,但现在即使使用新的构建也会出现问题.
一个特定的错误:我创建一个Deflater对象deflater = new Deflater();,设置一些输入deflater.setInput(buffer, 0, bufferPosition);,然后尝试通过突出显示一段代码deflater.needsInput()
并执行右键单击 - >检查来检查功能.错误内容为:"无法找到对象apps.TestCore $ Tests(id = 27)的字段deflater".
仅当字段属于内部类时才会发生错误(在本例中为"测试"); 当变量是本地的或者类不是内部类时,一切似乎都在起作用.将鼠标悬停在变量"deflater"上会显示内容向下钻取.突出显示"deflater"并执行Inspect会产生错误,并使用"表达式"视图检查变量上的变量/调用方法会产生相同的错误.
请帮忙; 这使我的调试生活变得非常困难,因为我必须使用println()比悬停检查更复杂的东西.
这不是远程调试 - 只是我的系统本地.
我正在为Java中的View分配一个OnClick监听器,如下所示:
public class MenuButton extends Fragment {
MenuButton self = this;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
MenuButton button = self;
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望获得对菜单按钮的引用,并将其用于我的onTouch方法中的内容(与我认为的问题无关).我知道我可以调用类的方法(例如getApplication())但我特别想要在匿名OnTouchListener中声明对象的引用.
正如你所看到的,我找到了一个解决方案!MenuButton self = this; 线.
有没有一种正确的方法可以做到这一点,还是我的奇怪解决方案唯一的方法呢?
我正在试图弄清楚如何创建一个方法来查找数组中的字符串并将其与其索引一起打印出来.我认为方法签名是正确的但我无法弄清楚如何在方法中返回字符串值.
String name = search(array,"Dog"); //the method implementation in main
System.out.println(name);
Run Code Online (Sandbox Code Playgroud)
.
public static int search(String[] array, String key)
{
for (int i= 0; i< array.length; i++)
{
if ( array[i] == key )
return i;
}
return ("Name cannot be found in array);
}
Run Code Online (Sandbox Code Playgroud) 当我尝试访问m.name = "killer"类内部时,无法找到变量错误.请帮忙.
class Movie {
String name;
String genre;
int num;
public void play()
{
System.out.println("start playing");
}
}
public class MovieObjects{
public static void main(String[] args) {
MovieObjects m = new MovieObjects ();
{
m.name="Killer";
m.genre = "Romance";
}
}
}
Run Code Online (Sandbox Code Playgroud)