小编Ash*_*wal的帖子

Spring正在挑选一个接口实现,而不是自己的?

下面的朋友是我的代码,我试图用Spring运行依赖注入

我有一个接口,该接口的两个类实现.

一个bean.xml和一个main方法类.

接口IWriter.java

package DI;
    public interface IWriter {
    public void writer(String s);
}  
Run Code Online (Sandbox Code Playgroud)

类Writer.java

     package DI;

     import org.springframework.stereotype.Service;

     @Service
     public class Writer implements IWriter {
        public void writer (String s){
            System.out.println(s);
        }
     } 
Run Code Online (Sandbox Code Playgroud)

类NiceWriter.java

package DI;

import org.springframework.stereotype.Service;

@Service
public class NiceWriter implements IWriter {
    public void writer (String s){
        System.out.println("The string is " + s);
    }
} 
Run Code Online (Sandbox Code Playgroud)

另一堂课

package DI;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class MySpringBeanWithDependency {

    @Autowired
    private IWriter writer;

    public void …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

10
推荐指数
2
解决办法
8262
查看次数

CKEditor关闭对话框

我正在尝试从我的自定义插件调用CKEditor对话框的close函数.就像当你点击"smileys"插件中的微笑时发生的那样,但我无法找到我如何在自己的插件中做同样的事情.谢谢回复!

我有解决方案.在我的插件中,我需要在"onLoad"部分中调用"CKEDITOR.dialog.add"中的close函数.所以,我必须这样做:

CKEDITOR.dialog.add( 'plugin_name', function( editor ){
    onLoad: function( event ){
        [...some code...]
        event.sender.hide();
    }
}
Run Code Online (Sandbox Code Playgroud)

ckeditor

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

<init>和(Native Method)是什么意思?

这些符号表示什么以及(Native方法)对该java.io.FileStream.open方法的说法是什么?

Exception in thread "main" java.io.FileNotFoundException: line23 (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:135)
at java.io.FileInputStream.<init>(FileInputStream.java:95)
at java.io.FileReader.<init>(FileReader.java:64) at Helper.readFile(Foo5.java:74)
at Bar2.main(Bar2.java:32)
Run Code Online (Sandbox Code Playgroud)

java methods native init filenotfoundexception

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

如何在Java中针对Schematron模式验证文档?

据我所知,JAXP默认支持Java 6中的W3C XML Schema和RelaxNG.

我可以在schematron.com链接页面上看到一些API,主要是实验性的或不完整的.

是否有一种方法可以验证Java中的schematron是否完整,高效且可以与JAXP API一起使用?

java validation schema jaxp schematron

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

在JAXP中使用XPath检索XML节点和节点属性的值

给定一个如下所示的xml文档:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <entry key="agentType">STANDARD</entry>
    <entry key="DestinationTransferStates"></entry>
    <entry key="AgentStatusPublishRate">300</entry>
    <entry key="agentVersion">f000-703-GM2-20101109-1550</entry>
    <entry key="CommandTimeUTC">2010-12-24T02:25:43Z</entry>
    <entry key="PublishTimeUTC">2010-12-24T02:26:09Z</entry>
    <entry key="queueManager">AGENTQMGR</entry>
</properties>
Run Code Online (Sandbox Code Playgroud)

我想打印"key"属性和元素的值,所以它看起来像这样:

agentType = STANDARD
DestinationTransferStates = 
AgentStatusPublishRate = 300
agentVersion = f000-703-GM2-20101109-1550
CommandTimeUTC = 2010-12-24T02:25:43Z
PublishTimeUTC = 2010-12-24T02:26:09Z
queueManager = AGENTQMGR
Run Code Online (Sandbox Code Playgroud)

我可以使用此代码打印节点值没有问题:

XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//properties/entry/text()");

Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
    System.out.println(nodes.item(i).getNodeValue()); 
} …
Run Code Online (Sandbox Code Playgroud)

java xml xpath jaxp

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

使用timezone java将字符串转换为适当的日期

我正在使用它的时区日期,我想将它转换为另一个时区,例如我有Date'3/15/2013 3:01:53 PM',这是在TimeZone'GMT-06:00'.我想在'GMT-05:00'时区转换它.我有搜索很多,而且我对如何实际日期工作感到困惑.如何应用时区到目前为止.我尝试使用SimpleDateFormat,Calender以及偏移量.

DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aaa XXX");
df.setTimeZone(TimeZone.getTimeZone("GMT")); 
Date dt = null;
try {
    dt = df.parse("3/15/2013 3:01:53 PM -06:00");
} catch (ParseException e) {
    e.printStackTrace();
} 
String newDateString = df.format(dt);
System.out.println(newDateString);
Run Code Online (Sandbox Code Playgroud)

它返回输出 03/15/2013 09:01:53 AM Z.我想它应该是 03/15/2013 09:01:53 PM Z,因为在'GMT-06:00'时区的时间,所以在GMT中得到时间应该是HH + 6.我希望Date以"yyyy-MM-dd HH:mm:ss"格式,其中HH在24小时内.请帮我举个例子.提前致谢.

编辑:

我正在使用SimpleDateFormat将字符串转换为日期

DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aaa");
    Date dt = null;
    try {
        dt = df.parse("3/15/2013 3:01:53 PM");
    } catch (ParseException e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

现在,正如你所说,我指定日历我的日期属于'GMT-06:00'时区并设定我的日期,

Calendar cal …
Run Code Online (Sandbox Code Playgroud)

java timezone date

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

使用Merge Sort排序(名称)

有问题排序重复字符串,

这是我的代码..

我成功排序了第一个数组,但在第二个数组(重复的字符串)似乎没有有序输出,你能帮我跟踪我的代码中的错误吗?

import java.util.*;

public class NewClass {
    public static void main(String[] args) {
        String[] ClassOne = { "Kring", "Panda", "Soliel", "Darryl", "Chan", "Matang", "Jollibee.", "Inasal" };
        String[] ClassTwo = { "Minnie", "Kitty", "Madonna", "Miley", "Zoom-zoom", "Cristine", "Bubbles", "Ara", "Rose", "Maria" };
        String[] names = new String[ClassOne.length + ClassTwo.length];

        mergeSort(ClassOne);
        mergeSort(ClassTwo);

        merge(names, ClassOne, ClassTwo);

        mergeSort(names);
        //Arrays.sort(names);

        for (String ClassThree : names) {
            System.out.println(ClassThree);
        }
    }

    public static void mergeSort(String[] names) {
        if (names.length > 2) {
            String[] left = …
Run Code Online (Sandbox Code Playgroud)

java arrays sorting merge

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

正则表达式不适用于jquery验证插件

我正在使用下面的代码

$(function() {
    $("#myForm").validate({
        rules: {
            experience: {
                required: true,
                regex: '^[0-9]$'
            }
        },
        messages: {
            experience: {
                required: "Please provide experience",
                regex: "Provide a valid input for experience"
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

但上面的代码不是2或22作为有效输入?我做错了什么?需要帮助......

regex jquery jquery-validate

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

获取响应文件使用ExtJS

我使用ExtJS为我的程序构建客户端.有一种情况我想向服务器发送Ajax请求,并获取响应文件(二进制文件,而不是纯文本文件,即XLS或PDF).如何通过ExtJS获取返回的文件(我的意思是该文件可以下载并存储到客户端)?我不能var result = Ext.decode(response.responseText)用来接收结果,因为响应包含二进制数据并且无法解码.

Ajax调用非常简单:

Ext.Ajax.request({
    url : 'myController/exportFile',
    method : 'GET',
    success : function(response, opts) {
        // What should I do to get the file?
    },
    failure : function(response, opts) {
        alert('Export file failed!')
    }
});
Run Code Online (Sandbox Code Playgroud)

这是我的服务器操作返回文件:

public void sendFile(HttpServletResponse response, String filePath) {
        def file = new File(filePath);
        response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment;filename=${file.getName()}");     
        response.outputStream << file.newInputStream();
    }
Run Code Online (Sandbox Code Playgroud)

非常感谢!

extjs file response

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

javax.xml.bind.JAXBException:类<ClassName>也不知道它的任何超类

我有一个RESTful Web服务,我正在使用Java 1.6在Tomcat 6上部署,我看到了一些奇怪的行为.我正在使用大约5个其他war文件部署这个特定的war文件.有问题的Web应用程序还定期以xml格式向远程服务器发送状态消息,所有XML绑定都是使用JAXB 2.1.13完成的.初始部署后,JAXB绑定似乎无法正常工作.也就是说,如果我启动tomcat并等待状态消息被发送,我会收到以下错误:

javax.xml.bind.JAXBException: class StatusMessage nor any of its super class is known to this context. 
Run Code Online (Sandbox Code Playgroud)

(为简洁起见,我省略了完全限定的类名).对RESTful服务的任何传入请求也会抛出相同的异常.

如果我在每次战争中打包所有库,我都没有看到这个问题,但是我试图不这样做,因为我的WAR文件变得非常臃肿.JAX库被包装在这场战争中,但像Spring这样的东西, commons-*,hibernate,在tomcat/lib中.有没有人有任何想法可能导致这种奇怪的部署顺序敏感性?

这里有一些代码细节,每次触发状态消息时都会发生以下情况:

JAXBElement<StatusMessage> el = ( new ObjectFactory() ).createHeartbeat( statusMessage );
ApiUtils apiUtil = new ApiUtils();

NamespaceFilter outFilter = new NamespaceFilter("http://middleware/status", true);
String xml = apiUtil.makeXml( el, "com.package.path.status", ApiUtils.getFormatXMLSetting(), ApiUtils.getValidateXMLSetting(), outFilter);
Run Code Online (Sandbox Code Playgroud)

makeXML调用如下所示:

public String makeXml(JAXBElement el, String packageName, Boolean formatXml, Boolean validateXml, NamespaceFilter outFilter) throws JAXBException,
SAXException, UnsupportedEncodingException, IOException{

    // Marshal XML
    JAXBContext jaxbContext = JAXBContext.newInstance( packageName );
    Marshaller …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat jaxb

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