小编Mor*_*ndi的帖子

如何将war文件添加到另一个java Web应用程序依赖项?

我有web maven项目.Project的输出是一个war文件.我想将此war文件添加为project_b的依赖项.
project_b的pom.xml文件有一个插件如下:

...
<plugin>
    <inherited>true</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <warName>geoserver</warName>
        <webappDirectory>${project.build.directory}/geoserver</webappDirectory>
        <packagingExcludes>WEB-INF/lib/servlet-api*.jar</packagingExcludes>
        <archive>
            <manifest>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
            </manifest>
            <manifestEntries>
                <GeoServerModule>core</GeoServerModule>
                <Application-Name>${project.build.finalname}</Application-Name>
                <Project-Version>${project.version}</Project-Version>
                <Iteration-Name>${iteration}</Iteration-Name>
                <Build-Timestamp>${maven.build.timestamp}</Build-Timestamp>
                <Git-Revision>${build.commit.id}</Git-Revision>
            </manifestEntries>
        </archive>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>war</goal>
            </goals>
        </execution>
    </executions>
</plugin>
...
Run Code Online (Sandbox Code Playgroud)

如何添加的warWeb应用程序与到project_b <groupId>org.itsme</groupId>,<artifactId>spring3-mvc-maven-xml-hello-world</artifactId>,<packaging>war</packaging><version>1.0-SNAPSHOT</version>

java web-applications maven-plugin

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

如何在Hibernate中动态添加实体?

我是一名java开发人员.我正在使用spring 4.0.1hibernate 4.2.21.我有一个课程如下:

@Entity
@Inheritance(...)
public abstract class Feature{
   @Id
   @GeneratedValue
   protected Long id;

   ...

}
Run Code Online (Sandbox Code Playgroud)

现在我有很多课程如下:

Label.java类:

@Entity
public class Label extends Feature{
   protected String str;

   ...
}
Run Code Online (Sandbox Code Playgroud)

Point.java类:

@Entity
public class Point extends Feature{
   protected Integer intg;

   ...
}
Run Code Online (Sandbox Code Playgroud)

我有超过20个从Feature类扩展的Entity 类.有没有办法在没有编写硬代码的情况下动态地将这些类(例如LabelPoint)添加到项目中?

更新:

例如,Hibernate从数据库中获取数据,然后根据这些数据创建模型.

  1. 可能吗?
  2. 我该怎么办?

java hibernate spring-mvc datapersistance

16
推荐指数
3
解决办法
6969
查看次数

如何使用ModelMapper进行深度继承对象?

A.java

@Entity
@Getter
@Setter
@Inheritance
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, inclue=JsonTypeInfo.As.PROPERTY, property="type") 
@JsonSubTypes({
    @JsonSubTypes.Type(value=AA.class,name="aa"),
    @JsonSubTypes.Type(value=AB.class,name="ab"),
})
public abstract class A {
    @Id
    @GeneratedValue
    private Long id;

    //json ignore for getter
    @ManyToOne
    private A parent;

    @OneToMany(mappedBy="parent")
    private List<A> children;
}
Run Code Online (Sandbox Code Playgroud)

AA.java

@Entity
@Getter
@Setter
@DiscriminatorValue("aa")
public class AA extends A{
    private User user;
}
Run Code Online (Sandbox Code Playgroud)

AB.java

@Entity
@Getter
@Setter
@DiscriminatorValue("ab")
public class AB extends A {
    private String name;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我将类的实例AB作为JSON 返回时,它看起来像这样:

{
     "id": 1,
     "type": "ab",
     "children": [...],
     "name": "ali"
}
Run Code Online (Sandbox Code Playgroud)

由于我想使用自定义User …

java dto modelmapper

15
推荐指数
1
解决办法
621
查看次数

如何使用spring websocket向自定义用户发送自定义消息?

我是弹簧websocket的新手.我想将产品更改发送给客户.为此,我想按如下方式执行:客户端创建套接字连接并订阅目标:

var socket = new SockJS('/websocket');
var stompClient = Stomp.over(socket);

stompClient.connect({}, function (frame) {
    stompClient.subscribe('/product/changes', function (scoredata) {
        // We received product changes
    });
});
//Send Ajax request and say server I want to know product with id=5 changes.
sendAjaxRequest(5);
Run Code Online (Sandbox Code Playgroud)

我已将弹簧应用程序配置如下:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/product/");
        registry.setApplicationDestinationPrefixes("/app");
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我需要以下方法:

@RestController
public class ProductController {

    @GetMapping("product-{id}")
    public void startSubscribe(@PathVariable("id") Long …
Run Code Online (Sandbox Code Playgroud)

java spring sockjs spring-boot spring-websocket

13
推荐指数
1
解决办法
2355
查看次数

如何在同一实体中使用多个@Embedded?

我在 Java Web 应用程序中有一个可嵌入的实体,如下所示:

@Embeddable
@Getter
@Setter
public class Address {
   private String street;
   private String alley;
   private int postCode;
}
Run Code Online (Sandbox Code Playgroud)

我在另一个实体中使用了一个嵌入字段,如下所示:

@Entity
@Getter
@Setter
public class User {

    @Embedded
    private Address home;

    @Embedded
    private Address work;
}
Run Code Online (Sandbox Code Playgroud)

当我运行应用程序时,发生错误:

org.hibernate.MappingException:实体映射中的重复列:my.package.User 列:alley(应映射为 insert="false" update="false")。

我该如何解决?

笔记:

  • 我不能用@AttributeOverrides
  • 我正在使用休眠 5.2.10。

更新: 我使用的配置applicationContext.xml如下:

<bean id="mainSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="packagesToScan"> 
        <list> 
            <value>my.package</value> 
        </list> 
    </property> 

    <property name="hibernateProperties"> 
        <props> 
            <prop key="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</prop> 
            <prop key="hibernate.hbm2ddl.auto">update</prop> 
            <prop key="hibernate.connection.characterEncoding">UTF-8</prop> 
            <prop key="hibernate.connection.charSet">UTF-8</prop> 
            <prop key="hibernate.default_schema">public</prop> …
Run Code Online (Sandbox Code Playgroud)

java hibernate

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

如何在Spring Boot 2 oauth2中获得令牌?

我是Spring Security oauth2的新手。我要运行此授权服务器示例代码。我成功运行了它,为了获得令牌,我将邮递员设置为如下,然后发送请求:

基本认证 赠款类型

在这种情况下,我输入了带有其密码的客户端ID,但是我想在没有它们的情况下登录。例如,我的用户发送用户名,密码和客户端ID,然后获取令牌。但是我发送的每个请求,服务器都返回401响应。在Spring boot 2 oauth 2中,我该怎么做?

java spring-security spring-boot spring-security-oauth2

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

如何在 jsonb 列上使用 Spring JPA 进行查询?

我正在将 spring JPA 与 PostgreSQL 数据库一起使用。我有一个实体如下:

@Entity
@TypeDef(name="json_binary", typeClass = com.vladmihalcea.hibernate.type.json.JsonBinaryType.class)
public class LiveTokens {

   @Id
   @GeneratedValue()
   private Long id;

   private String username;

   @Type(type="json_binary")
   @Column(columnDefinition = "jsonb")
   private Token token
}
Run Code Online (Sandbox Code Playgroud)

Token

public class Token {
   private Long expireTime;
   private String accessToken;
}
Run Code Online (Sandbox Code Playgroud)

为了使用Hibernate将对象保存到列,我使用了Hibernate Types项目。现在我想获得LiveToken过期的All 。我不能用 Spring JPA 做到这一点。如何使用 Spring 数据 JPA 查询 posgresql jsonb 列?

java postgresql spring hibernate spring-data-jpa

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

如何使用apache tomcat 8部署geoserver web存档?

我想web archive在我的tomcat网络服务器上运行geoserver .我正在使用tomcat 8.
web archivegeoserver下载GeoServer 2.7.1.1 .当我想部署war文件时,出现错误如下: 在此输入图像描述

但是当我部署另一个war应用程序时,它正确部署.

哪里有问题?

webarchive geoserver tomcat8

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

hibernate动态组件等效注解

在 hibernate 中通过注释定义动态组件的等效方法是什么?

public abstract class CustomizableEntity {

 private Map customProperties;

 public Map getCustomProperties() {
         if (customProperties == null)
             customProperties = new HashMap();
        return customProperties;
 }
 public void setCustomProperties(Map customProperties) {
        this.customProperties = customProperties;
 }

 public Object getValueOfCustomField(String name) {
     return getCustomProperties().get(name);
 }

 public void setValueOfCustomField(String name, Object value) {
     getCustomProperties().put(name, value);
 }

 }
Run Code Online (Sandbox Code Playgroud)

我的实体:

public class Contact extends CustomizableEntity {

 private int id;
 private String name;

 public int getId() {
     return id;
 }

 public void setId(int id) {
     this.id …
Run Code Online (Sandbox Code Playgroud)

java annotations hibernate dynamic hibernate-mapping

5
推荐指数
0
解决办法
1016
查看次数

如何在没有管理员角色的情况下通过 REST 获取 Keycloak 用户信息

我使用keycloak作为授权服务器。用户将自己的用户名/密码发送到MyWebAppMyWebApp获取grant_type: password令牌,然后将令牌响应给用户。现在我希望我的用户能够获取他们的信息,更改他们的密码以及与他们自己相关的一切RESTFUL。当我发送休息请求以/{realm}/users/{id}获取用户信息时,keycloak 收到 403 错误响应。如何在没有 keyclaok 管理员访问权限的情况下获取用户信息?

注意:我已经看到这个问题,但我也想给用户编辑个人资料。

keycloak keycloak-services

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

如何使用jpa在postgresql中将继承类列表保存为json?

为了在 postgresql 中保存 json 格式的列表,我com.vladmihalcea:hibernate-types-52在 Spring boot 2 中使用如下:

@Entity
@TypeDefs({
    @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class Profile {
    ...
    @Type(type = "jsonb")
    @Column(columnDefinition = "jsonb")
    private List<String> locations;

    // getters & setters
}
Run Code Online (Sandbox Code Playgroud)

有了这个,一切都OK了,我可以将位置保存为postgresql中的json。但我想将位置保存为类继承结构。课程如下:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property = "type")
@JsonSubTypes({
    @JsonSubTypes.Type(value = SubClass1.class, name = "subClass1"),
    @JsonSubTypes.Type(value = SubClass2.class, name = "subClass2")
})
public abstract class MyClass {
    private String name;
    // getters & setters
}
public class SubClass1 extends …
Run Code Online (Sandbox Code Playgroud)

java jackson spring-boot postgresql-json jackson-databind

5
推荐指数
0
解决办法
1012
查看次数

如何实现自定义spring security acl?

我正在使用 Spring 开发应用程序。在访问控制访问部分,我想使用 Spring Security Acl(我是 Acl 的新手)。我想基于 2 点在我的应用程序中实现 ACL:

  1. 应用程序应具有五个权限readcreatemodifydeleteAdministrator
  2. 权限是层次结构,当用户有create权限,它应该能够read,或者当它有modify权限,它应该可以readcreatemodify等。

是否可以?如何?

更新
我的应用程序基于 Spring MVC RESTFUL。当用户想要修改自己的信息时,他用ajax发送一些json数据。json数据示例如下:

{
  "id": 1,//user Id
  "name": "my name",
  "password": "my password",
  "email": "email@email.com",
   ...
}
Run Code Online (Sandbox Code Playgroud)

现在,恶意用户可以登录自己的帐户。该用户可以modify像所有其他用户一样拥有自己的数据。在他发送数据之前,更改他的id,以及modify另一个帐户的用户信息。我想用 ACL 来防止这种颠覆性的工作。并且用户可以访问其他人可以修改他的信息的其他人。

java spring acl spring-security spring-security-acl

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