是否可以从脚本更改当前目录?
我想在Bash中为目录导航创建一个实用程序.我创建了一个如下所示的测试脚本:
#!/bin/bash
cd /home/artemb
Run Code Online (Sandbox Code Playgroud)
当我从Bash shell执行脚本时,当前目录不会更改.是否可以从脚本中更改当前的shell目录?
我有一个插件(antrun),其执行配置具有id并且不绑定到任何阶段.我可以直接从命令行执行此执行吗?
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>my-execution</id>
...
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
用它来运行它:
mvn my-execution
Run Code Online (Sandbox Code Playgroud)
或至少
mvn magicplugin:execute -DexecutionId=my-execution
Run Code Online (Sandbox Code Playgroud) 我使用ektorp连接到CouchDB.
构建ektorp HttpClient
实例的方法是使用构建器模式:
HttpClient httpClient = new StdHttpClient.Builder()
.host("mychouchdbhost")
.port(4455)
.build();
Run Code Online (Sandbox Code Playgroud)
我对Spring比较陌生.请告诉我如何HttpClient
在我的上下文中配置一个来创建它Builder
.
一种方法是这样做@Configuration
.还有其他选择吗?
java spring dependency-injection builder inversion-of-control
我正在使用Spring Security 3.0.4.我有一堆受Spring Security保护的Web服务.当我以未经身份验证的用户身份访问它们时,Spring Security会重定向到登录页面.而不是那样,我想返回HTTP 403错误.我怎样才能做到这一点?
这是我的安全配置:
<http auto-config="false" use-expressions="true" >
<intercept-url pattern="/authorization.jsp" access="permitAll"/>
<intercept-url pattern="/registration.jsp" access="permitAll"/>
<intercept-url pattern="/api/authorization/auth" access="permitAll"/>
<intercept-url pattern="/api/authorization/new" access="permitAll"/>
<intercept-url pattern="/api/accounts/new" access="permitAll"/>
<intercept-url pattern="/app/**" access="permitAll"/>
<intercept-url pattern="/extjs/**" access="permitAll"/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
<form-login login-page="/authorization.jsp"
default-target-url="/index.jsp"
authentication-failure-url="/registration.jsp?login_error=1"
always-use-default-target="true"
/>
<logout logout-success-url="/authorization.jsp"
logout-url="/j_spring_security_logout"
invalidate-session="true"/>
</http>
Run Code Online (Sandbox Code Playgroud) 想象一下,您正在使用Hibernate和JBoss开发Java EE应用程序.您有一个正在运行的服务器,其中包含一些重要数据.您偶尔会发布下一个版本的应用程序(1-2周),并且它们在持久层中有一堆更改:
您如何有效地设置更新数据库模式并保留数据的系统?据我所知(我可能会误会),Hibernate不会执行alter column,drop/alter constraint.
谢谢你,Artem B.
文档说如果你有一个上下文文件:
$CATALINA_HOME/conf/Catalina/localhost/myapp.xml
Run Code Online (Sandbox Code Playgroud)
它不会被上下文文件替换:
mywebapp.war/META-INF/context.xml
Run Code Online (Sandbox Code Playgroud)
它写在这里:http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
仅当$ CATALINA_BASE/conf/[enginename]/[hostname] /中的应用程序不存在上下文文件时,才在应用程序文件内的/META-INF/context.xml中的单个文件中.
但是每当我重新部署战争时,它都会用/META-INF/context.xml替换这个myapp.xml!
它为什么这样做,我该如何避免呢?
感谢名单
我正在开发一个基于Spring的应用程序,它注册一个自定义范围"任务".我们的想法是,当一个新的Task启动时,Spring应该提供任务范围的对象.
该任务在运行时中实例化.它以Properties
对象的形式提供一些配置.我想ApplicationContext
在任务范围内注册该对象,以便该范围内的所有bean都可以引用该特定任务的配置.
这是代码中的粗略思想:
public class MyTask extends SourceTask {
@Override
public void start(Map<String, String> props) {
context = ContextProvider.getApplicationContext();
// Initialize the scope
ConnectorTaskScope scope = context.getBean(ConnectorTaskScope.class);
scope.startNewTask();
// TODO register the props object in the context
// get an object which requires the properties and work with it
context.getBean(SomeScopedBean.class);
}
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何在ApplicationContext
适当范围内注册bean .
谢谢
更新:
这里有一些代码可以更好地解释这个问题.SomeScopedBean
应该使用bean提供的配置做一些事情,看起来像这样:
public class SomeScopedBean {
@Autowire
public SomeScopedBean (Properties configuration) {
// …
Run Code Online (Sandbox Code Playgroud) 我从CouchDB开始.使用数据库的最佳做法是什么?每个应用程序的单个数据库存储各种具有类似"_type"属性的smth的实体,以区分彼此或为每种实体区分单独的数据库?
我使用hibernate作为持久层.有两个实体位于同一个表中,扩展了一个具有单表继承策略的超类.
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class A {
@Id
@GeneratedValue
protected Long id;
// some common fields for B and C
}
@Entity
public class B extends A {
// B-specific fields
}
@Entity
public class C extends A {
// C-specific fields
}
Run Code Online (Sandbox Code Playgroud)
我有一个ID为4的B实例.如何将此实例的类型更改为C保留其ID(4)?
B b = em.find(B.class, 4L);
C c = convertToC(b);
c.setId(b.getId());
em.remove(b);
em.persist(c);
Run Code Online (Sandbox Code Playgroud)
上面的代码失败了
org.hibernate.PersistentObjectException: detached entity passed to persist: C
Run Code Online (Sandbox Code Playgroud)
有可能吗?
我有这个问题已经有很长一段时间了,我已经在网上搜索了SO而且还没有找到解决方案.我希望你能帮助我.
我在两个实体之间有一个父子关系,如下所示:
@Entity
public class Parent {
// ...
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
private Set<Child> children = new HashSet<Child>();
// ...
}
@Entity
public class Child {
// ...
@ManyToOne(fetch = FetchType.LAZY)
private Parent parent;
// ...
}
Run Code Online (Sandbox Code Playgroud)
问题在于,当我创建一个新子节点并将其分配给父节点时,父节点在缓存中时不会更新.
Parent parent = new Parent();
em.persist(parent);
// ...
Child child = new Child();
child.setParent(parent);
em.persist(child);
parent.getChildren().size(); // returns 0
Run Code Online (Sandbox Code Playgroud)
当孩子被持久化时,我曾尝试使用@PreUpdate自动将子项添加到父项,但是当我们在2个不同的线程中有2个实体管理器时(比如JBoss),问题仍然存在,直到我们调用 em.refresh(parent)
所以问题是 - 有没有办法顺利消除问题并确保parent.getChildren()
始终返回最新的儿童名单?
hibernate ×3
java ×3
spring ×3
persistence ×2
bash ×1
builder ×1
caching ×1
couchdb ×1
database ×1
deployment ×1
environment ×1
maven-2 ×1
migrate ×1
one-to-many ×1
parent-child ×1
schema ×1
tomcat ×1
tomcat6 ×1