我正在尝试使用Spring 3.0(和maven)完成我的第一个项目.我在相当多的项目中一直使用Spring 2.5(和引物版本).不过我有点困惑,我必须在我的pom.xml中定义哪些模块作为依赖项.我只想使用核心容器函数(bean,core,context,el).
我习惯这样做:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但现在我有点困惑,因为3.0版本没有完整的弹簧模块.我尝试了以下但它没有用(有些类缺失).
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
虽然java.io.RandomAccessFile确实有一种close()方法java.io.File没有.这是为什么?文件是否在最终确定时自动关闭?
谢谢!
返回ModelAndView的方式
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ModelAndView list(
@UserAuth UserAuth user,
ModelAndView mav) {
if (!user.isAuthenticated()) {
mav.setViewName("redirect:http://www.test.com/login.jsp");
return mav;
}
mav.setViewName("list");
mav.addObject("articles", listService.getLists());
return mav;
}
Run Code Online (Sandbox Code Playgroud)
返回String的方式
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(
@UserAuth UserAuth user,
Model model) {
if (!user.isAuthenticated()) {
return "redirect:http://www.test.com/login.jsp";
}
model.addAttribute("articles", listService.getLists());
return "list";
}
Run Code Online (Sandbox Code Playgroud)
这些工作相同.哪个更好?有什么区别?
我已经看到用于描述列表和堆栈等数据结构的术语intrusive,但它是什么意思?
您能给出一个侵入式数据结构的代码示例,以及它与非侵入式数据结构的区别吗?
另外,为什么要使它具有侵入性(或非侵入性)?有什么好处?有什么缺点?
我想使用Fabric将我的Web应用程序代码部署到开发,登台和生产服务器.我的fabfile:
def deploy_2_dev():
deploy('dev')
def deploy_2_staging():
deploy('staging')
def deploy_2_prod():
deploy('prod')
def deploy(server):
print 'env.hosts:', env.hosts
env.hosts = [server]
print 'env.hosts:', env.hosts
Run Code Online (Sandbox Code Playgroud)
样本输出:
host:folder user$ fab deploy_2_dev
env.hosts: []
env.hosts: ['dev']
No hosts found. Please specify (single) host string for connection:
Run Code Online (Sandbox Code Playgroud)
当我创建Fabric文档中set_hosts()显示的任务时,env.hosts设置正确.但是,这不是一个可行的选择,也不是装饰者.在命令行上传递主机最终会导致调用fabfile的某种shell脚本,我宁愿让一个工具正常工作.
它在Fabric文档中说'env.hosts只是一个Python列表对象'.根据我的观察,这根本不是真的.
谁能解释一下这里发生了什么?如何设置要部署的主机?
你好,我需要在linux中这样做:
怎么做?谢谢!
我在java中发现很多书说switch语句比if语句更快.但我没有找到说明为什么开关比如果更快的地方.
我有一种情况我必须选择两个中的任何一项我可以使用以下任一方式
switch(item){
case BREAD:
//eat Bread
break;
default:
//leave the restaurant
}
Run Code Online (Sandbox Code Playgroud)
或使用if语句如下
if(item== BREAD){
//eat Bread
}else{
//leave the restaurant
}
Run Code Online (Sandbox Code Playgroud)
考虑项目和BREAD是常量int值
在上面的例子中,哪个更快,为什么?
我用jUnit的@BeforeClass注释标记了一个方法,得到了这个例外,说它必须是静态的.理由是什么?这迫使我所有的init都在静态字段上,据我所知,这是没有充分理由的.
在.Net(NUnit)中,情况并非如此.
编辑 - 使用@BeforeClass注释的方法只运行一次与静态方法无关 - 可以使非静态方法只运行一次(如在NUnit中).
CodeSign错误:证书身份'iPhone Developer:XXXX(12345678)'在钥匙串中出现不止一次.代码签名工具要求只有一个.
所以我去我的钥匙串并删除它.但是每次重新启动Xcode 4时都会出现此错误,而某些应用程序会将过期的旧证书添加回钥匙串.任何想法为什么和哪个应用?
为什么enum的构造函数不能访问静态字段和方法?这对于类非常有效,但不允许使用枚举.
我要做的是将我的枚举实例存储在静态Map中.考虑这个允许通过abbreivation查找的示例代码:
public enum Day {
Sunday("Sun"), Monday("Mon"), Tuesday("Tue"), Wednesday("Wed"), Thursday("Thu"), Friday("Fri"), Saturday("Sat");
private final String abbreviation;
private static final Map<String, Day> ABBREV_MAP = new HashMap<String, Day>();
private Day(String abbreviation) {
this.abbreviation = abbreviation;
ABBREV_MAP.put(abbreviation, this); // Not valid
}
public String getAbbreviation() {
return abbreviation;
}
public static Day getByAbbreviation(String abbreviation) {
return ABBREV_MAP.get(abbreviation);
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为枚举不允许在其构造函数中使用静态引用.然而,如果实现为类,它只能找到:
public static final Day SUNDAY = new Day("Sunday", "Sun");
private Day(String name, String abbreviation) {
this.name = name;
this.abbreviation = abbreviation;
ABBREV_MAP.put(abbreviation, …Run Code Online (Sandbox Code Playgroud) java ×5
c ×1
c++ ×1
code-signing ×1
controller ×1
dependencies ×1
enums ×1
fabric ×1
file-io ×1
host ×1
iphone ×1
junit ×1
linux ×1
maven-2 ×1
objective-c ×1
python ×1
spring ×1
spring-mvc ×1
symlink ×1
terminology ×1
xcode4 ×1