我正在关注http://spring.io/guides/tutorials/data/3 ; 我不确定我做错了什么,但我继续得到我不理解的异常.我尝试使用相同的例外搜索问题但无济于事.
堆栈跟踪: http ://pastebin.com/WYPqS6da
PersistenceConfig.java
@Configuration
@EnableJpaRepositories
@EnableTransactionManagement
public class PersistenceConfig {
@Bean
public DataSource dataSource() throws SQLException {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder.setType(EmbeddedDatabaseType.HSQL).build();
}
@Bean
public EntityManagerFactory entityManagerFactory() throws SQLException {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(Database.HSQL);
vendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("com.scrumster.persistence.domain");
factory.setDataSource(dataSource());
factory.afterPropertiesSet();
return factory.getObject();
}
@Bean
public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
return entityManagerFactory.createEntityManager();
}
@Bean
public PlatformTransactionManager transactionManager() throws SQLException {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory());
return …Run Code Online (Sandbox Code Playgroud) 是否有一种替代方法可用于lodash,下划线或其他几乎表现相同的库,除了它返回一个新对象而不是改变第一个参数?
var o = { 'user': 'barney' }
var result = method(o, { 'age': 40 }, { 'user': 'fred' })
// o still { 'user': 'barney' }
// result is now { 'user': 'fred', 'age': 40 }
Run Code Online (Sandbox Code Playgroud) 正如标题所说,我有一个资源对象Product扩展ResourceSupport.但是,我收到的回复具有属性"_links"而不是"links",并且具有不同的结构.
{
"productId" : 1,
"name" : "2",
"_links" : {
"self" : {
"href" : "http://localhost:8080/products/1"
}
}
}
Run Code Online (Sandbox Code Playgroud)
基于HATEOAS参考,预期是:
{
"productId" : 1,
"name" : "2",
"links" : [
{
"rel" : "self"
"href" : "http://localhost:8080/products/1"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是有意的吗?有没有办法改变它,或者如果不是结构那么就是"链接"?
我通过以下代码段添加了selfLink:
product.add(linkTo(ProductController.class).slash(product.getProductId()).withSelfRel());
Run Code Online (Sandbox Code Playgroud)
我使用以下构建文件的spring boot:
dependencies {
compile ("org.springframework.boot:spring-boot-starter-data-rest") {
exclude module: "spring-boot-starter-tomcat"
}
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-jetty"
compile "org.springframework.boot:spring-boot-starter-actuator"
runtime "org.hsqldb:hsqldb:2.3.2"
testCompile "junit:junit"
}
Run Code Online (Sandbox Code Playgroud) 我想为我的存储库公开新的端点,这也扩展了RevisionRepository.
@RepositoryRestResource(collectionResourceRel = "persons", itemResourceRel = "person", path = "persons")
public interface PersonRepository extends PagingAndSortingRepository<PersonEntity, Long>, RevisionRepository<PersonEntity, Long, Integer> {
Revision<Integer, PersonEntity> findLastChangeRevision(@Param("id") Long id);
Revisions<Integer, PersonEntity> findRevisions(@Param("id") Long id);
Page<Revision<Integer, PersonEntity>> findRevisions(@Param("id") Long id, Pageable pageable);
PersonEntity findByName(@Param("name") String name);
}
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,这些新方法不会作为网址(findLastChangeRevision,findRevisions)公开,只会findByName在搜索网址下.我目前对于实际的网址形式并不是特别关注,只要它有效.
我现在知道的唯一选择是
我对上面的选项有很多保留意见.我不知道该怎么办.
我想根据对象的类型执行几个操作,而不使用instanceof.起初我正在考虑基于类型重载方法(如下所示),并认为Java可能会适当地选择方法(基于最具体的对象类).
import java.util.ArrayList;
import java.util.List;
public class TestA {
public static void main(String[] args)
{
List<Object> list = new ArrayList();
list.add(new A());
list.add(new B());
list.add(new C());
list.add(new Object());
TestA tester = new TestA();
for(Object o: list)
{
tester.print(o);
}
}
private void print(A o)
{
System.out.println("A");
}
private void print(B o)
{
System.out.println("B");
}
private void print(C o)
{
System.out.println("C");
}
private void print(Object o)
{
System.out.println("Object");
}
}
class A {
}
class B extends A { …Run Code Online (Sandbox Code Playgroud) 关于这个问题,我检查了Spring Data Rest Ambiguous Association Exception但是无法让它为我工作.
正如您在下面的代码中看到的,我添加了@RestResource与rel其他值相等的注释.
与上面的问题类似,POST请求有效,但GET请求会抛出具有相同关系类型的多个关联链接的异常:
"无法编写JSON:检测到具有相同关系类型的多个关联链接!消除关联@ org.springframework.data.rest.core.annotation.RestResource(rel = createdBy,exported = true,path =,description =@org.springframework. data.rest.core.annotation.Description(value =))@ javax.persistence.ManyToOne(optional = true,targetEntity = void,cascade = [],fetch = EAGER)@ javax.persistence.JoinColumn(referencedColumnName = ASSIGNABLE_ID,nullable = false,unique = false,name = CREATED_BY,updatable = true,columnDefinition =,foreignKey = @ javax.persistence.ForeignKey(name =,value = CONSTRAINT,foreignKeyDefinition =),table =,insertable = true)private com.ag. persistence.domain.PersonEntity com.ag.persistence.domain.TeamEntity.createdBy使用@RestResource!(通过引用链:org.springframework.hateoas.PagedResources [\"_ embedded \"] - > java.util.UnmodifiableMap [\"people \"] - > java.util.ArrayList [0]);嵌套异常是com.fasterxml.jackson.databind.JsonMappingException:检测到多个关联 具有相同关系类型的链接!消除关联@ org.springframework.data.rest.core.annotation.RestResource(rel = createdBy,exported = true,path =,description = @ org.springframework.data.rest.core.annotation.Description(value …
鉴于以下内容:
var average = R.lift(R.divide)(R.sum, R.length)
Run Code Online (Sandbox Code Playgroud)
为什么这会作为一个无点的实现average?我不明白为什么我可以通过R.sum,R.length当它们是函数时,因此,我无法映射提升R.divide函数,R.sum而R.length不像下面的例子:
var sum3 = R.curry(function(a, b, c) {return a + b + c;});
R.lift(sum3)(xs)(ys)(zs)
Run Code Online (Sandbox Code Playgroud)
另外,在上述情况下,在值xs,ys和zs相加在一个非确定性上下文中,在这种情况下,提升函数被应用到的值在给定的计算上下文.
进一步阐述,据我所知,施加解除功能就像使用R.ap连续到每个参数.两行都评估相同的输出:
R.ap(R.ap(R.ap([tern], [1, 2, 3]), [2, 4, 6]), [3, 6, 8])
R.lift(tern)([1, 2, 3], [2, 4, 6], [3, 6, 8])
Run Code Online (Sandbox Code Playgroud)
检查文档说:
"提升"arity> 1的函数,以便它可以"映射"满足FantasyLand Apply规范的列表,函数或其他对象.
这对我来说似乎不是一个非常有用的描述.我正试图建立一个关于使用的直觉lift.我希望有人可以提供.
每当尝试运行时mvn install,在Spring Boot项目上构建都会因以下原因而失败:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.3:在项目wave上编译(default-compile):致命错误编译:java.lang.RuntimeException:com.sun.tools.javac.code.符号$ CompletionFailure:未找到org.springframework.security.ldap.DefaultSpringSecurityContextSource的类文件 - > [帮助1]
有两件事解决了这个问题:
删除以下安全配置
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Inject
private UserDetailsService userDetailsService;
@Inject
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.realmName("Wave")
.and()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/wave/service/employees/**").anonymous()
.antMatchers("/wave/service/**").authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
}
Run Code Online (Sandbox Code Playgroud)对于coruse,删除配置不是一个选项,因为它会禁用我的应用程序的安全性
添加 …
我有以下文件夹结构:
/index.html
/app/index.tsx
Run Code Online (Sandbox Code Playgroud)
与 webpack 捆绑后,我希望将以下输出目录与 bundle.js 注入 index.html
/dist/index.html
/dist/app/bundle.js
/dist/app/bundle.js.map
Run Code Online (Sandbox Code Playgroud)
我有以下 webpack 配置
var webpack = require("webpack")
var HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = [
{
entry: "./app/index",
output: {
path: "./dist/app",
filename: "bundle.js"
},
devtool: "source-map",
resolve: {
extensions: ["", ".tsx", ".ts", ".js"]
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new HtmlWebpackPlugin({
"filename": "./index.html",
"template": "html!./index.html"
})
],
module: {
loaders: [
{ test: /\.tsx?$/, loader: "ts-loader" },
]
}
},
{
output: {
path: "./dist",
filename: "bundle.js"
},
plugins: …Run Code Online (Sandbox Code Playgroud) 我的 application.properties 中有以下属性。
spring.profiles.active=dev,local
Run Code Online (Sandbox Code Playgroud)
这工作正常。但是,我决定也将其作为环境变量公开并保留dev,local为默认值。但是,以下不起作用。
spring.profiles.active=${PROFILES_ACTIVE:dev,local}
Run Code Online (Sandbox Code Playgroud)
似乎逗号会导致此问题。
检查日志
[2018-05-24 05:38:28.163] [main] [INFO] [Application] The following profiles are active: ${PROFILES_ACTIVE:dev,local}
Run Code Online (Sandbox Code Playgroud)
但是,以下工作。
spring.profiles.active=${PROFILES_ACTIVE:dev}
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何建议?
java ×7
spring ×6
javascript ×3
spring-boot ×2
spring-data ×2
gradle ×1
hateoas ×1
lifting ×1
lodash ×1
maven ×1
polymorphism ×1
ramda.js ×1
spring-mvc ×1
webpack ×1