我有关于泛型的Java问题.我宣布了一个通用名单:
List<? extends MyType> listOfMyType;
Run Code Online (Sandbox Code Playgroud)
然后在某些方法中我尝试实例化并将项添加到该列表:
listOfMyType = new ArrayList<MyType>();
listOfMyType.add(myTypeInstance);
Run Code Online (Sandbox Code Playgroud)
哪里myTypeInstance只是一个类型的对象MyType; 它不会编译.它说:
该方法在类型List <capture#3-of中添加(捕获#3-of?extends MyType)?extends MyType>不适用于参数(MyType)
任何的想法?
我正在尝试将我们的网站从.Net 3.5迁移到4,我遇到了一个非常奇怪的问题.
一旦我以.Net4为目标,在3.5中工作得很好的代码就不再存在了,给了我错误
"语言不支持xxx".
TimeZoneInfo tzi = !calendarItem.UseUserTimeZone ? user.Settings.TimeZoneInfo : l.TimeZoneItem.Info;
Run Code Online (Sandbox Code Playgroud)
在该行代码中,错误显示在" .TimeZoneInfo"和" .Info"两个类型" System.TimeZoneInfo"上.
user.Settings.TimeZoneInfo财产的定义是:
public TimeZoneInfo TimeZoneInfo
{
get { return World.TimeZones[Convert.ToInt32(this[Setting.TimeZoneInfo])].Info; }
set { this[Setting.TimeZoneInfo] = value.ToTimeZoneItem().Id.ToString(); }
}
Run Code Online (Sandbox Code Playgroud)
l.TimeZoneItem.Info财产的定义是:
public TimeZoneInfo Info
{
get { return info; }
}
Run Code Online (Sandbox Code Playgroud)
不确定这里发生了什么.请帮助那个.
我目前正在.Net中设计一个小应用程序,过去我一直使用MSAccess作为独立的数据库,我可以随程序一起提供.但我想知道在这个时代是否没有替代解决方案,因为易于集成到.Net应用程序中,对用户来说是透明的,而且对于大量数据可能会有更好的性能?
我必须清理一个旧项目,这里的一般知识是该项目包含许多我们可以删除的未使用的代码.这样可以省去一些麻烦并使维护更容易.
我发现Eclipse Core Tools插件看起来像一个很棒的工具,但在我们的例子中,我们有一个Maven2项目,它分为3个模块.我似乎无法在父项目上运行"查找未引用的成员",当我在其中一个模块上运行它时,它完全忽略了其他模块可能正在使用某些公共成员的事实......
任何人都克服了这个问题?或者找到另一种方法来解决这个问题?
谢谢.
我目前正在评估消息队列系统,RabbitMq似乎是一个很好的候选者,所以我正在深入研究它.
为了给出一些上下文,我希望有一个类似于一个交换负载的东西来平衡消息发布到多个队列.我不想复制邮件,因此不能选择扇出交换.
另外我之所以考虑拥有多个队列而不是一个队列来处理与消费者的循环,我不希望我们的单点故障处于队列级别.
听起来我可以在发布者端添加一些逻辑来通过编辑路由键并具有适当的绑定来模拟该行为.但这种被动方法不会考虑每个队列上的消息消耗速度,如果该队列的消费者应用程序已经死亡,可能会导致填满一个队列.
我正在寻找一种来自交换实体方面的更主动的方式,它将根据每个队列大小或某种性质决定在何处发送下一条消息.
我读到了Alice和可用的RESTful API,但这似乎是实现快速路由决策的重要解决方案.
任何人都知道如果在交换队列之间循环是否可行,那么RabbitMQ呢?谢谢.
我有一个List<MyObj>用class MyObj : IComparable.我按照接口CompareTo在MyObj类中编写了方法IComparable,但是当我使用List<MyObj>.Contains(myObjInstance)它false时,它应该返回它true.
我不确定我是否理解我需要继续确保List在调用then Contains函数时使用我的自定义比较方法.
这是我的compareTo实现:
#region IComparable Members
public int CompareTo(object obj)
{
MyObj myObj = (MyObj)obj;
return String.Compare(this.Symbol, myObj.Symbol, true);
}
#endregion
Run Code Online (Sandbox Code Playgroud)
请注意,Symbol属性是一个字符串.
为了澄清我已经在compareTo方法中设置了一个停止点,它甚至没有进入那里.
有人试过吗?
谢谢.
所以我有一点Linux问题,geez会教我在Windows上度过这么多年.无论如何,我做了一个小的Java应用程序,很好地包装了Java Service Wrapper脚本,但是当我运行该脚本时:
sh ./wrapper.sh console
Run Code Online (Sandbox Code Playgroud)
我马上得到了许可.权限被拒绝的消息是这样的:
eval: 1: /home/user1/MyApp/bin/wrapper: Permission denied
Run Code Online (Sandbox Code Playgroud)
我的小wrapper.sh位于MyApp/bin文件夹中.目录MyApp/bin/wrapper包含2个文件:
作为测试,我运行了以下chmod命令:
chmod a=rwx MyApp -R
Run Code Online (Sandbox Code Playgroud)
我验证了所有内容都是rwx,即使在子文件夹中并尝试再次运行脚本,结果完全相同...权限被拒绝.
任何人都知道我可以尝试下一步让宝宝跑步吗?
谢谢,兰斯洛特
我有2台机器坐在我的桌子上并连接到同一个IP网络.我正在尝试将应用程序从一台机器连接到另一台机器上的postgres数据库.首先,带有应用程序的主机给我PSQLException:
FATAL: no pg_hba.conf entry for host "192.168.1.18", user "user1", database "test", SSL off
Run Code Online (Sandbox Code Playgroud)
所以我编辑了我的pg_hba.conf文件以接受IP地址:192.168.1.18,在文件末尾添加以下行:
host pnp all 192.168.1.18 trust
Run Code Online (Sandbox Code Playgroud)
然后我得到另一种类型的错误消息:
FATAL: missing or erroneous pg_hba.conf file
Run Code Online (Sandbox Code Playgroud)
这里有什么我想念的吗?
谢谢,兰斯洛特
我试图拦截任何带有自定义注释标记的方法,你读这个的原因是因为我无法让它工作.我一直在关注简单的例子,但无法让它发挥作用.
这是我的代码.
MyAnnotation.java:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
String value() default "";
String key() default "";
String condition() default "";
}
Run Code Online (Sandbox Code Playgroud)
MyAspect.java:
@Aspect
public class MyAspect {
@Pointcut(value="execution(public * *(..))")
public void anyPublicMethod() { }
@Around("anyPublicMethod() && @annotation(myAnnotation)")
public Object process(ProceedingJoinPoint jointPoint, MyAnnotation myAnnotation) throws Throwable {
System.out.println("In AOP process");
return 5; //jointPoint.proceed();
}
}
Run Code Online (Sandbox Code Playgroud)
春天-config.xml文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/cache …Run Code Online (Sandbox Code Playgroud) 所以我正在使用Spring Security处理这个Spring MVC应用程序.在我的控制器花费太长时间响应的某些情况下,我一直遇到性能问题.这是由于一种处理方法,可以根据一些用户输入处理大量数据.
现在我和我的团队一直在调整代码和处理方法,我不认为我们可以在没有切片并异步执行每个切片的情况下获得更好的性能.
问题是当我尝试将它分割并将工作分发给子线程时,使用来自java.util.concurrent的线程池,当执行这些时,我得到有关安全上下文的错误消息.
这是stacktrace的摘录:
Exception in thread "pool-1-thread-3" org.springframework.security.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
at org.springframework.security.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:342)
at org.springframework.security.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:254)
at org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:63)
Exception in thread "pool-1-thread-4" at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy63.batchSaveCampaignpayment(Unknown Source)
at com.fim.pnp.controller.PaymentForm$1.run(PaymentForm.java:224)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)
org.springframework.security.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
at org.springframework.security.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:342)
at org.springframework.security.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:254)
at org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:63)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy63.batchSaveCampaignPayment(Unknown Source)
at com.fim.pnp.controller.PaymentForm$1.run(PaymentForm.java:224)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650) …Run Code Online (Sandbox Code Playgroud)