我主要用Java编写代码并使用Maven来完成我的所有项目.我真的很喜欢使用Maven,因为它很容易下载源代码和文档,更重要的是,我不需要在我的项目源代码文件夹下保留外部库的副本.
我已经开始开发一个Android应用程序,我发现eclipse的Android插件非常好.但是,所有提供的示例都不是maven项目,因此我不知道,如果我使用maven,我仍然可以从Android插件获得所有功能,或者使用Maven是否有任何缺点.
所以问题是:
请不要指向Android项目的maven支持?
我想从经验丰富的开发人员那里得到答案 我已经知道可以将maven用于Android应用程序.我需要知道的是我是否应该使用它.
我试图在我的Web应用程序中使用Spring Security 3.0.5.基本上,我想拥有一个以json格式返回数据的Web服务HTTP GET.
我已经实现了一个RESTful服务,它在http://localhost:8080/webapp/json请求url时返回数据.使用以下curl命令可以正常工作
> curl http://localhost:8080/webapp/json
{"key":"values"}
Run Code Online (Sandbox Code Playgroud)
使用spring security添加基本身份验证后,我可以使用以下命令获取数据
> curl http://localhost:8080/webapp/json
<html><head><title>Apache Tomcat/6.0.29 - Error report .....
> curl -u username:password http://localhost:8080/webapp/json
{"key":"values"}
Run Code Online (Sandbox Code Playgroud)
前一个命令返回标准的tomcat错误页面,因为它现在需要用户名和密码.我的问题是,是否有可能以打印出我自己的错误消息的方式处理拒绝访问?即
> curl http://localhost:8080/webapp/json
{"error":"401", "message":"Username and password required"}
Run Code Online (Sandbox Code Playgroud)
这是我的spring安全配置和AccessDeniedHandler.正如您所看到的,我正在尝试添加access-denied-handler哪个只是通过servlet响应打印出一个字符串,但它仍然不会在命令行上打印我自己的消息.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<global-method-security secured-annotations="enabled"/>
<beans:bean name="access-denied" class="webapp.error.JSONAccessDeniedHandler"></beans:bean>
<http auto-config="true">
<access-denied-handler ref="access-denied"/>
<intercept-url pattern="/json" access="ROLE_USER,ROLE_ADMIN" />
<http-basic />
</http>
<authentication-manager>
<authentication-provider>
<password-encoder …Run Code Online (Sandbox Code Playgroud) 有没有人有经验或知道什么时候该方法File.getCanonicalPath()会抛出一个IOException
我试图从互联网上查找,最好的答案是在File API中说的
" IOException- 如果发生I/O错误,这是可能的,因为规范路径名的构造可能需要文件系统查询"
但是,我不清楚,因为我仍然无法想到这可能会失败的情况.谁能给我具体的例子,可以在Linux,Windows和其他操作系统上发生(可选)?
我之所以想知道是因为我想相应地处理这个异常.因此,如果我知道可能发生的所有可能的故障,那将是最好的.
在我看来web.xml,默认的servlet映射,即/映射到Spring调度程序.在我的Spring调度程序配置中,我有DefaultAnnotationHandlerMapping,ControllerClassNameHandlerMapping并且AnnotationMethodHandlerAdapter允许我通过其类名或@Requestmapping注释将url映射到控制器.但是,Web根目录下有一些静态资源,我也希望spring调度程序使用默认的servlet来提供服务.根据Spring文档,这可以使用<mvc:default-servlet-handler/>tag 完成.
在下面的配置中,我标记了4个可以插入此标记的候选位置.将标记插入不同的位置会导致调度程序的行为方式如下:
情况1:如果我将其插入位置1,调度程序将无法再通过@RequestMapping和控制器类名称处理映射,但它将正常提供静态内容.
Cas 2,3:它能够处理@RequestMapping和控制器类名称的映射,以及如果无法成功完成其他映射,则提供静态内容.
情况4:它无法提供静态内容. 删除注意:这是一个实现控制器时的错误,该控制器具有映射到/**但在控制器类名上没有显式请求映射的方法.
因此,案例2和3是可取的.根据Spring文档,这个标签配置一个处理程序,其优先顺序被赋予最低,那么为什么位置很重要?哪个是放置此标签的最佳位置?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="webapp.controller"/>
<!-- Location 1 -->
<!-- Enable annotation-based controllers using @Controller annotations -->
<bean id="annotationUrlMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<!-- Location 2 -->
<bean id="controllerClassNameHandlerMapping" class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<!-- Location 3 -->
<bean id="annotationMethodHandlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> …Run Code Online (Sandbox Code Playgroud) 有谁知道如何使循环播放嵌入式YouTube视频?
我已经尝试过从官方youtube开发者网站生成的代码,但它根本不起作用.视频在Firefox和Chrome中结束后,它不会重播.这是生成的代码不起作用.
<object style="height: 390px; width: 640px">
<param name="movie" value="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&loop=1">
<param name="allowFullScreen" value="true">
<param name="allowScriptAccess" value="always">
<embed src="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&loop=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344">
</object>
Run Code Online (Sandbox Code Playgroud)
我试过去谷歌,但没有任何好的指示.
在中readFileMethod1,IOException在将其抛出到方法级别之前显式捕获,以确保finally执行该块.但是,是否需要捕获异常?如果我删除catch块,如图所示readFileMethod2,finally块也会被执行吗?
private void readFileMethod1() throws IOException {
try {
// do some IO stuff
} catch (IOException ex) {
throw ex;
} finally {
// release resources
}
}
private void readFileMethod2() throws IOException {
try {
// do some IO stuff
} finally {
// release resources
}
}
Run Code Online (Sandbox Code Playgroud) 我对此示例的 spring-security bean配置非常相似.@Secured控制器方法的注释只有在不是另一个类的子类的方法上才能正常工作.换句话说,以下代码不起作用(在bean初始化期间引发的异常):
@Controller
@RequestMapping("/systeminfo")
public class SystemInfoController extends AbstractViewableController {
@RequestMapping(method = RequestMethod.GET, value = "/")
@Secured("ROLE_USER") // an exception below was raised
public void view(HttpServletRequest request) {
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'systemInfoController' defined in file [C:\workspace\my\my-webapp
\target\classes\my\webapp\controller\SystemInfoController.class]: Initializa
tion of bean failed; nested exception is org.springframework.aop.framework.AopCo
nfigException: Could not generate CGLIB subclass of class [class my.webapp.c
ontroller.SystemInfoController]: Common causes of this problem include using a f
inal class or …Run Code Online (Sandbox Code Playgroud) 我打算构建一个桌面应用程序,它将使用Hibernate和MySQL作为其数据源.我想在多台机器上执行桌面应用程序,但我希望它们都能读/写同一个MySQL数据库.这甚至可能吗?当两个应用程序试图访问/修改相同的信息时,我担心的是并发问题.是否存在多个ORM应用程序的替代解决方案,以实现实时数据库同步(如果不允许单个数据库)?
在stackoverflow上有一些类似的问题,但他们的答案不满足我.
我想在后台用户请求后执行一些任务.我最初的想法是创建一个工作线程并从servlet执行它.但是,我不希望同时运行太多线程,因此我需要类似线程池的东西.
由于我已经在我的Web应用程序中使用Spring,我想知道Spring或其他库中是否有任何东西可以用来处理这个问题而无需实现我自己的代码.
Spring文档以下列方式定义@Component注释:"表示带注释的类是"组件".当使用基于注释的配置和类路径扫描时,这些类被视为自动检测的候选者."
这很简洁,但并没有说太多.我知道@Component用于表示Spring将管理类生命周期(创建/销毁).我有的问题:我只需要在某个地方自动装配的类中使用它(1)或者我是否还需要在具有自动装配属性的类中使用它(2)?
(1)
@Component
class B {
}
class A {
// @Autowired
B b;
}
Run Code Online (Sandbox Code Playgroud)
(2)
@Component
class B {
}
@Component
class A {
// @Autowired
B b;
}
Run Code Online (Sandbox Code Playgroud) java ×9
spring ×3
spring-mvc ×2
android ×1
file-io ×1
hibernate ×1
html ×1
javascript ×1
maven ×1
mysql ×1
servlets ×1
threadpool ×1
youtube ×1