小编sti*_*vlo的帖子

为什么Facebook不使用jQuery(或类似的)?

Facebook基于JavaScript.为什么它不依赖于jQuery(或任何其他类似的库)?

编辑:为何关闭此问题?这不是主观的.facebook不使用jQuery(或任何其他框架)是有原因的,我要求的.

javascript jquery frameworks facebook

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

在机器上获取所有IP地址

如何获取连接到我的应用程序(C#NET控制台应用程序)运行的计算机的所有IP地址?我需要将WCF服务绑定到主IP地址,并返回完整IP地址列表的列表.

using System.Net;

string myHostName = Dns.GetHostName().ToString();
string ipAddress = Dns.Resolve(HostName).AddressList[0].ToString();
Run Code Online (Sandbox Code Playgroud)

这就是我现在正在使用的获取主IP地址,但我无法弄清楚如何让其余的返回它们.

如果我将WCF服务绑定到localhost:8000,是否会在主服务器上公开它?

.net c# ip wcf networking

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

Maven构建号码插件,如何在文件中保存构建号码?

我有一个使用Spring Framework和Git的Java项目,我想显示一个内部版本号.我找到了Build Number Maven插件.使用Git,内部版本号是一个Git哈希.我不喜欢这个,我认为约会更有表现力.

我发现这篇优秀的博客文章解释了如何使用不同的SVN和Git配置文件编号插件.由于我只使用Git,而不是创建新的配置文件,我只是在我的构建标记中复制了插件部分.

当我运行"mvn package"时,它告诉我:

[INFO] --- buildnumber-maven-plugin:1.0:create (default) @ sherd ---
[INFO] Storing buildNumber: 2011-08-04_21-48_stivlo at timestamp: 1312487296631
Run Code Online (Sandbox Code Playgroud)

哪个看起来不错,但我想知道,它存放在哪里?"git status"没有检测到任何新文件,它似乎不在目标/中(目标/在我的.gitignore中).

也许我要更改配置以将内部版本号存储在文件中?如何使用内部版本号值?


感谢Michael-O的提示,我在Maven入门指南中阅读了有关如何过滤资源文件的章节.我在src/main/resources/properties/application.properties中创建了一个文件application.properties,其中包含以下内容:

# application properties
application.name=${pom.name}
application.version=${pom.version}
application.build=${buildNumber}
Run Code Online (Sandbox Code Playgroud)

我在构建部分中添加了以下XML代码段:

<resources>
    <resource>
        <directory>src/main/resources/properties</directory>
        <filtering>true</filtering>
    </resource>
</resources>
Run Code Online (Sandbox Code Playgroud)

现在,当我从命令行"mvn package"调用时,此属性文件将保存在target/classes/properties/application.properties中,例如具有以下内容:

# application properties
application.name=Sherd Control Panel
application.version=1.0.1-SNAPSHOT
application.build=2011-08-05_05-55_stivlo
Run Code Online (Sandbox Code Playgroud)

从命令行一切正常,但是,叹息,m2eclipse给出了Build错误:

05/08/11 6.05.03 CEST: Build errors for obliquid-cp; 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
org.codehaus.mojo:buildnumber-maven-plugin:1.0:create (default) on project 
sherd: Cannot get the branch information from …
Run Code Online (Sandbox Code Playgroud)

build maven-plugin maven buildnumber-maven-plugin

20
推荐指数
2
解决办法
3万
查看次数

是否有多个JdbcTemplate实例?

据我了解,无论是DataSourceJdbcTemplatesthreadsafe,那么您可以配置的一个实例JdbcTemplate,然后安全地注入该共享引用到多个DAO(或仓库).也DataSource应该是Spring单例,因为它管理连接池.

官方的Spring文档JdbcTemplate最佳实践解释了替代方案(手册的摘录用斜体,方括号之间的注释:

  • 在Spring配置文件中配置DataSource,然后将共享DataSource bean依赖注入到DAO类中; JdbcTemplate是在DataSource的setter中创建的.[使用XML配置,这导致多个JdbcTemplate实例,因为在数据源设置器中有new JdbcTemplate(dataSource)]
  • 使用组件扫描和注释支持依赖注入.在这种情况下,您使用@Repository注释该类(这使其成为组件扫描的候选者)并使用@Autowired注释DataSource setter方法.[也是这种情况导致多个JdbcTemplate实例]
  • 如果您正在使用Spring的JdbcDaoSupport类,并且您的各种JDBC支持的DAO类从它扩展,那么您的子类将从JdbcDaoSupport类继承setDataSource(..)方法.您可以选择是否继承此类.JdbcDaoSupport类仅为方便起见而提供.[因为你为每个扩展它的类都有一个JdbcDaoSupport实例,所以对于派生类的每个实例都有一个JdbcTemplate实例(参见JdbcDaoSupport的源代码)]

但是,稍后的说明会阻止刚刚提出的所有选项:

配置完成后,JdbcTemplate实例就是线程安全的.如果您的应用程序访问多个数据库(可能需要多个DataSource,以及随后多个不同配置的JdbcTemplates),您可能需要多个JdbcTemplate实例.

换句话说,刚才提出的所有选项都会导致有多个JdbcTemplate实例(每个DAO一个),并且在文档说明在使用单个数据库时不需要这样做.

我要做的是直接注入JdbcTemplate需要它的各种DAO,所以我的问题是,这样做是否可以?而且,您是否也认为Spring参考文档是自相矛盾的?还是我的误会?

java spring jdbctemplate

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

maven谷歌应用引擎项目中数据核增强器的冲突版本

我在设置datanucleus增强器时遇到问题,需要与谷歌应用程序引擎项目一起使用.如果我使用datanucleus eclipse插件一切顺利,但在我的maven项目中,我得到一个奇怪的冲突版本错误.

我的POM有这些数据核参考:

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>1.1.0</version>
</dependency>

...

<plugin>
    <groupId>org.datanucleus</groupId>
    <artifactId>maven-datanucleus-plugin</artifactId>
    <version>1.1.0</version>
    <configuration>
        <mappingIncludes>**/*.class</mappingIncludes>
        <verbose>true</verbose>
        <enhancerName>ASM</enhancerName>
        <api>JDO</api>
    </configuration>
    <executions>
        <execution>
        <phase>compile</phase>
        <goals>
            <goal>enhance</goal>
        </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

当我尝试构建项目时,我收到以下错误:

Exception in thread "main" Plugin (Bundle) "org.datanucleus" is already registered. 
Ensure you dont have multiple JAR versions of the same plugin in the classpath. The URL "file:/Users/drome/.m2/repository/org/datanucleus/datanucleus-core/1.1.0/**datanucleus-core-1.1.0.jar**" is already registered, and you are trying to register an identical plugin located at URL "file:/Users/drome/.m2/repository/org/datanucleus/datanucleus-core/1.1.3/**datanucleus-core-1.1.3.jar**."
org.datanucleus.exceptions.NucleusException: Plugin (Bundle) "org.datanucleus" is already registered. Ensure …

google-app-engine maven-2 datanucleus

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

如何获得高质量的缩略图

我正在尝试使用Java和Scalr 3.2创建此图像的高质量缩略图

全尺寸图像

这是相关的源代码,其中THUMB_WIDTH = 77THUMB_HEIGHT = 57

BufferedImage srcImg = ImageIO.read(new File(sourceFile)); 
BufferedImage dstImg = Scalr.resize(srcImg, Scalr.Method.QUALITY, 
    THUMB_WIDTH, THUMB_HEIGHT); 
ImageIO.write(dstImg, format, new File(destFile));
Run Code Online (Sandbox Code Playgroud)

如果我使用format = "png",结果如下:

png缩略图

如果我使用format = "jpg",结果如下:

jpg缩略图

通过imagemagick识别,我发现JPEG的质量保存为75,完全不足以创建美观的缩略图.PNG对我来说也不好看.

以下是原始文件的标识输出和两个缩略图:

$ identify 42486_1.jpg 42486_s1.jpg 42486_s1.png 
42486_1.jpg JPEG 580x435 580x435+0+0 8-bit DirectClass 50.6KB 0.000u 0:00.000
42486_s1.jpg[1] JPEG 77x58 77x58+0+0 8-bit DirectClass 2.22KB 0.000u 0:00.000
42486_s1.png[2] PNG 77x58 77x58+0+0 8-bit DirectClass 12.2KB 0.000u 0:00.000
Run Code Online (Sandbox Code Playgroud)

问题

  • 如何提高生成的缩略图的质量?
  • 如何保存质量更高的JPEG?我想尝试更高的质量并比较结果.我在JavaDoc for ImageIO.write中找不到任何东西. …

java java-2d image-resizing scalr

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

如何在Spring中找到当前webapp的基本URL?

我想从Controller中找到Spring中webapp的绝对URL.我知道JSTL c:url,但我需要来自Controller内部的这些信息.

@Controller
public class AuthorizeController {

    @Autowired
    private Authorizer auth;

    @RequestMapping("/auth")
    public String sendToAuthorization() {        
        String baseUrl = "http://localhost:8080/tasks/";
        return "redirect:" +  auth.getAuthorizationUrl(baseUrl);
    }

}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,baseUrl是硬编码的,我可以通过Spring配置将它提供给Authorizer类,但我确信可以在Controller中从Spring获取此信息.我试图google"spring mvc url"并找不到解决这个问题的方法.

java servlets spring-mvc

18
推荐指数
2
解决办法
4万
查看次数

在Symfony2中,如何在Controller中将链接重定向到带有锚标记/哈希的URL

我在控制器中,我想重定向回URL,比如/ home/news/example#comment1423

如何将哈希值添加到返回参数中?

return $this->redirect(
    $this->generateUrl("news_view", array("permalink" => "example"))
);
Run Code Online (Sandbox Code Playgroud)

routing symfony

18
推荐指数
2
解决办法
3万
查看次数

如何在使用Ruby重定向后获取最终的URL?

如果http://foo.com重定向到重定向到的1.2.3.4重定向http://finalurl.com,我如何使用Ruby找到登陆URL"http://finalurl.com"?

ruby networking redirect url-routing

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

tag0名称空间为默认名称空间中的元素添加

我正在尝试使用Groovy的XmlSlurper解析和修改Maven的pom.xml.我的pom.xml声明了名称空间xsi.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a-group-id</groupId>
<artifactId>an-artifact-id</artifactId>
Run Code Online (Sandbox Code Playgroud)

我的Groovy源代码如下:

import groovy.xml.XmlUtil
def pom = new XmlSlurper().parse('pom.xml')
   .declareNamespace('': 'http://maven.apache.org/POM/4.0.0',
      xsi: 'http://www.w3.org/2001/XMLSchema-instance')
//manipulate the pom
println XmlUtil.serialize(pom)
Run Code Online (Sandbox Code Playgroud)

正如您所注意到的,我已将第一个命名空间声明为空.但是在输出中,tag0随处可见.

<?xml version="1.0" encoding="UTF-8"?>
<tag0:project xmlns:tag0="http://maven.apache.org/POM/4.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
      http://maven.apache.org/maven-v4_0_0.xsd">
<tag0:modelVersion>4.0.0</tag0:modelVersion>
<tag0:groupId>a-group-id</tag0:groupId>
<tag0:artifactId>an-artifact-id</tag0:artifactId>
Run Code Online (Sandbox Code Playgroud)

怎么避免呢?

目前我的解决方法是手动删除标签:

println XmlUtil.serialize(pom).replaceAll('tag0:', '').replaceAll(':tag0', '')
Run Code Online (Sandbox Code Playgroud)

xml groovy parsing xmlslurper

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