javascript

java

python

c#

android

c++

node.js

php

html

jquery

ios

reactjs

css

.net

git

ruby-on-rails

sql

c

ruby

string

java-Spring Autowiring类与接口?

我有这个春天的配置:

<bean id="boo" class="com.x.TheClass"/>

TheClass实现了TheInterface。然后,我得到了这个(假设的)Java代码:

@Autowired
TheInterface x;

@Autowired
TheClass y;

TheInterface的自动接线有效,但TheClass的自动接线失败。 春天给我上了NoSuchBeanDefinitionException这堂课。

为什么可以连接接口而不是类?

trans by 2020-08-11T21:16:32Z

java-IntelliJ不会终止使用grad构建的Spring Boot应用程序

我在Linux上使用IntelliJ 13.1,并尝试根据示例[http://spring.io/guides/gs/spring-boot/]构建基本的REST应用程序

当我从IntelliJ中执行目标bootRun时,将启动集成的tomcat服务器,并且一切正常。

10:09:35: Executing external task 'bootRun'...
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:bootRun

但是停止执行不会影响gradle任务:

10:11:40: External task execution finished 'bootRun'.

我仍然可以在配置的端口上访问tomcat实例。 只有关闭IntelliJ才会破坏进程。

我搜索了这个主题,但找不到任何合理的答案。 我想知道这是否是

  • gradle问题(使用gradle包装器1.11版)
  • Linux问题(Ubuntu 12.04)
  • IntelliJ问题(IDEA 13.1.2)
  • Spring Boot问题(尝试从1.0.0.RELEASE到1.1.0.M2的不同版本)
trans by 2020-08-11T08:23:29Z

java-如何在<form:input>的属性内使用<spring:message>?

我有类似的JSP代码:

<div class="formRow">
    <form:input id="email_email" name="email_email" title="XXXXX"/>" path="email" cssClass="input required email" />
    <form:errors path="email" cssClass="error" />
</div>

我想用一些工具提示文本设置title属性,以支持i18n。 我该怎么做?

我正在寻找做这样的事情:

<div class="formRow">
    <form:input id="email_email" name="email_email" title="<spring:message code="tooltip.text" />"/>" path="email" cssClass="input required email" />
    <form:errors path="email" cssClass="error" />
</div>
trans by 2020-08-11T04:25:02Z

java-什么是“ spring-boot-starter”罐子?

在Spring Boot中,模式spring-boot-starter上有一些jar。所有这些jar不包含任何程序包。 它们有什么用?

在Maven POM中,添加了以下依赖项:

  • org.springframework.boot:spring-boot-starter-web
  • org.springframework.boot:spring-boot-starter-actuator
  • org.springframework.boot:spring-boot-starter-security

我实际上需要使用哪些Spring Boot jar来使用这些jar中的功能? 我的项目没有任何依赖项管理。 我的项目是使用Spring Security的Spring MVC应用程序。

trans by 2020-08-11T02:59:19Z

在Spring MVC中重定向到动态URL

我希望我的Spring MVC应用程序重定向到动态URL(由用户提交)。 所以如果我有这样的代码,

@RequestMapping("/redirectToSite")
protected ModelAndView redirect(
    @RequestParam("redir_url") String redirectUrl,
    HttpServletRequest request, 
    HttpServletResponse response) 
{
    // redirect to redirectUrl here
    return ?
}

我应该写些什么来重定向到提交的URL? 例如http://mySpringMvcApp/redirectToSite?redir_url=http://www.google.com应该重定向到Google。

trans by 2020-08-11T02:00:47Z

java-具有任意AND子句的动态spring数据jpa存储库查询

我正在使用Querydsl,但必须提供具有不同字段的搜索功能。 在搜索之前输入字段是可选的。我有5个字段,分别是nullcase 31 queries6,7,8...ProfessionDateOfBirth
在这里我只需要查询用户给定的值,其他字段应该被忽略。

Input : EmployeeNumber: ,Name:St,Married: ,Professsion:IT,DateOfBirth: 
Query : Select * from Employee e where Name like 'St%' and Profession like 'IT%';  

Input : EmployeeNumber:10,Name: ,Married: ,Professsion:IT,DateOfBirth:
Query : Select * from Employee e where EmployeeNumber like '10%' and Profession like 'IT%';  

因此,这里我们考虑输入的值和进行查询。 在这种情况下,Spring数据将受到本文中提到的限制(不可扩展,应编写所有可能的查询)我正在使用Querydsl,但是仍然存在问题,因为应该忽略null字段,并且几乎所有可能的查询都需要开发。 在此case 31 queries。如果搜索字段为6,7,8...怎么办?

用可选字段实现搜索选项的最佳方法是什么?

trans by 2020-08-10T22:57:01Z

java-在JSP EL表达式中获取Spring Security Principal

我正在使用Spring MVC和Spring Security版本3.0.6.RELEASE。 在我的JSP中获取用户名的最简单方法是什么? 甚至只是用户是否已登录? 我可以想到几种方法:

1.使用脚本

使用如下脚本来确定用户是否已登录:

<%=org.springframework.security.core.context.SecurityContextHolder.getContext()
    .getAuthentication().getPrincipal().equals("anonymousUser")
    ? "false":"true"%>

不过,我不喜欢使用scriptlet,我想在一些@Controller标签中使用它,这需要将其作为页面属性放回去。

2.使用SecurityContextHolder

我可以再次使用@Controller中的SecurityContextHolder并将其放在模型上。 不过,我在每个页面上都需要此逻辑,因此我宁愿不必在每个Controller中都添加此逻辑。

我怀疑有更干净的方法可以做到这一点...

trans by 2020-08-10T13:18:58Z

如何使用Spring Boot和Tomcat指定我的.keystore文件?

我正在尝试设置Spring Security以与Spring Boot的嵌入式Tomcat实例一起使用。 有很多基本示例可以执行此操作,但我被困在它们的后面,它们通过HTTP(不是HTTPS)执行基本身份验证。

如果可以访问Tomcat配置文件(server.xml),我可能可以使它工作,但是由于Spring Boot使用嵌入式Tomcat实例(否则非常方便),因此我无权访问Tomcat配置文件(至少不是) 据我所知)。

可能有server.xml的设置,但我无法对其进行跟踪。 我已经看到application.properties中对server.contextPath字段的引用,我怀疑这可能与替换Tomcat配置文件有关。 即使是相关的,我也不知道从哪里开始-我看到的所有Tomcat SSL指令都是从编辑现有的server.xml文件开始的,而不是从头开始构建。

可以使用Spring Boot来做到这一点(通过某种方式指定server.xml的片段或通过其他方式)吗? 如果没有,最简单的方法是什么? 我知道我可能需要排除Spring Boot的Tomcat组件,但如果可能的话,我宁愿避免这样做。

trans by 2020-08-09T18:50:24Z

java-终止mvn spring-boot:run不会停止tom

我可以使用mvn spring-boot成功启动spring-boot,该文档提到可以正常退出应用程序ctrl-c

Terminate batch job (Y/N)? Y

Maven进程确实终止了,但是Tomcat仍在运行,我仍然可以访问该网页。 当我尝试再次启动spring-boot时,由于端口正在使用中,因此无法启动Tomcat。

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v1.1.0.BUILD-SNAPSHOT)

2014-05-02 12:13:57.666  INFO 6568 --- [           main] Example                                  : Starting Example on challenger with PID 6568 (E:\workspace\SpringBoot\target\cla
sses started by steven in E:\workspace\SpringBoot)
2014-05-02 12:13:57.707  INFO 6568 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWeb
ApplicationContext@11ecab7c: startup date [Fri May 02 12:13:57 EDT 2014]; root of context hierarchy
2014-05-02 12:13:58.097  INFO 6568 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean
: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfi
gure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class pat
h resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; laz
yInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAuto
ConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfig
ure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2014-05-02 12:13:58.682  INFO 6568 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-05-02 12:13:58.892  INFO 6568 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2014-05-02 12:13:58.892  INFO 6568 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.53
2014-05-02 12:13:58.981  INFO 6568 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-05-02 12:13:58.981  INFO 6568 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1277 ms
2014-05-02 12:13:59.453  INFO 6568 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2014-05-02 12:13:59.455  INFO 6568 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2014-05-02 12:13:59.570 ERROR 6568 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Failed to start end point associated with ProtocolHandler ["http-nio-8080"]

java.net.BindException: Address already in use: bind
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:344)
        at sun.nio.ch.Net.bind(Net.java:336)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473)
        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:647)
        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:449)
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1007)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:459)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:79)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:69)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:270)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:145)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:159)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:680)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:930)
        at Example.main(Example.java:16)

2014-05-02 12:13:59.571 ERROR 6568 --- [           main] o.apache.catalina.core.StandardService   : Failed to start connector [Connector[org.apache.coyote.http11.Http11NioProtocol-
8080]]

org.apache.catalina.LifecycleException: Failed to start component [Connector[org.apache.coyote.http11.Http11NioProtocol-8080]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:459)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:79)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:69)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:270)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:145)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:159)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:680)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:930)
        at Example.main(Example.java:16)
Caused by: org.apache.catalina.LifecycleException: service.getName(): "Tomcat";  Protocol handler start failed
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1014)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 18 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:344)
        at sun.nio.ch.Net.bind(Net.java:336)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473)
        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:647)
        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:449)
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1007)
        ... 19 common frames omitted

2014-05-02 12:13:59.572  INFO 6568 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2014-05-02 12:13:59.580  INFO 6568 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/E:/workspace/SpringBoot/src/m
ain/resources, file:/E:/workspace/SpringBoot/src/main/resources, file:/E:/workspace/SpringBoot/target/classes/, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring
-boot-starter-web/1.1.0.BUILD-SNAPSHOT/spring-boot-starter-web-1.1.0.BUILD-SNAPSHOT.jar, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring-boot-starter/1.1.0.BUI
LD-SNAPSHOT/spring-boot-starter-1.1.0.BUILD-SNAPSHOT.jar, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring-boot/1.1.0.BUILD-SNAPSHOT/spring-boot-1.1.0.BUILD-SNA
PSHOT.jar, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.1.0.BUILD-SNAPSHOT/spring-boot-autoconfigure-1.1.0.BUILD-SNAPSHOT.jar, file:/C:
/Users/steven/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.1.0.BUILD-SNAPSHOT/spring-boot-starter-logging-1.1.0.BUILD-SNAPSHOT.jar, file:/C:/Users/steven/.
m2/repository/org/slf4j/jcl-over-slf4j/1.7.7/jcl-over-slf4j-1.7.7.jar, file:/C:/Users/steven/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar, file:/C:/Users/steven/.m2
/repository/org/slf4j/jul-to-slf4j/1.7.7/jul-to-slf4j-1.7.7.jar, file:/C:/Users/steven/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.7/log4j-over-slf4j-1.7.7.jar, file:/C:/Users/st
even/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar, file:/C:/Users/steven/.m2/repository/ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar, f
ile:/C:/Users/steven/.m2/repository/org/yaml/snakeyaml/1.13/snakeyaml-1.13.jar, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.1.0.BUILD
-SNAPSHOT/spring-boot-starter-tomcat-1.1.0.BUILD-SNAPSHOT.jar, file:/C:/Users/steven/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/7.0.53/tomcat-embed-core-7.0.53.jar, f
ile:/C:/Users/steven/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/7.0.53/tomcat-embed-el-7.0.53.jar, file:/C:/Users/steven/.m2/repository/org/apache/tomcat/embed/tomcat-e
mbed-logging-juli/7.0.53/tomcat-embed-logging-juli-7.0.53.jar, file:/C:/Users/steven/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.3.3/jackson-databind-2.3.3.jar, fi
le:/C:/Users/steven/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.3.0/jackson-annotations-2.3.0.jar, file:/C:/Users/steven/.m2/repository/com/fasterxml/jackson/co
re/jackson-core/2.3.3/jackson-core-2.3.3.jar, file:/C:/Users/steven/.m2/repository/org/springframework/spring-web/4.0.3.RELEASE/spring-web-4.0.3.RELEASE.jar, file:/C:/Users/steven/
.m2/repository/org/springframework/spring-aop/4.0.3.RELEASE/spring-aop-4.0.3.RELEASE.jar, file:/C:/Users/steven/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file
:/C:/Users/steven/.m2/repository/org/springframework/spring-beans/4.0.3.RELEASE/spring-beans-4.0.3.RELEASE.jar, file:/C:/Users/steven/.m2/repository/org/springframework/spring-cont
ext/4.0.3.RELEASE/spring-context-4.0.3.RELEASE.jar, file:/C:/Users/steven/.m2/repository/org/springframework/spring-core/4.0.3.RELEASE/spring-core-4.0.3.RELEASE.jar, file:/C:/Users
/steven/.m2/repository/org/springframework/spring-webmvc/4.0.3.RELEASE/spring-webmvc-4.0.3.RELEASE.jar, file:/C:/Users/steven/.m2/repository/org/springframework/spring-expression/4
.0.3.RELEASE/spring-expression-4.0.3.RELEASE.jar]
Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedde
d.EmbeddedServletContainerException: Unable to start embedded Tomcat
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
[INFO] ------------------------------------------------------------------------
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
[INFO] BUILD SUCCESS
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:680)
[INFO] ------------------------------------------------------------------------
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
[INFO] Total time: 4.653 s
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:930)
        at Example.main(Example.java:16)
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
[INFO] Finished at: 2014-05-02T12:13:59-05:00
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:106)
[INFO] Final Memory: 16M/232M
[INFO] ------------------------------------------------------------------------
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:69)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:270)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:145)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:159)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132)
        ... 7 more
Caused by: java.lang.IllegalStateException: Tomcat connector in failed state
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:102)
        ... 12 more

要继续,我必须手动终止正在运行的进程。 这是错误还是我错过了什么?

trans by 2020-08-09T13:33:27Z

春季-什么时候使用AbstractAnnotationConfigDispatcherServletInitializer和WebApplicationInitializer?

我正在使用Spring 4.0.7

我进行了有关通过JavaConfig配置Spring MVC的研究。

几乎直到昨天,我已经看到了使用这两个选项的两种配置

  1. 扩展AbstractAnnotationConfigDispatcherServletInitializer
  2. 扩展WebMvcConfigurerAdapter并实现WebApplicationInitializer

注意:(2)是两个类,一个用于扩展,另一个用于实现

我之所以使用(2),是因为我发现了许多可以配置转换器,格式化程序,资源处理程序等的示例。

但是在最近的日子里,我试图帮助解决有关StackOverflow的问题,但我确实意识到(1)存在。

我的问题是这篇文章的标题如何描述。

谢谢

trans by 2020-08-09T12:25:14Z

java-如何通过Spring安全性有条件地向登录用户显示jsp内容

我想向任何已登录的用户显示内容,并在未登录的情况下隐藏它们。我正在使用jsp和spring安全性。

显然,自行解决方案很容易做到。 但是实现这一目标的最干净的标准方法是什么?

Spring安全性标签似乎没有很好的方法来允许将来添加新角色。

trans by 2020-08-09T05:22:12Z

弹簧B的优势

我一直在尝试了解Spring Boot,并可能将我的项目迁移到其中。 但是,除了嵌入式Tomcat之外,我没有真正的优势。 您能否向我解释一下Spring Boot与普通Spring相比的真正力量是什么?

trans by 2020-08-09T03:25:20Z

java-在不使用Maven的情况下可以从哪里下载Spring Framework jars?

SpringSource.org将其站点更改为[http://spring.io]

有人知道如何在没有Maven / github的情况下获取最新版本吗? 来自[http://spring.io/projects]

trans by 2020-08-09T03:00:02Z

java-从持久性存储中加载会话的异常

我对春季诊所的应用程序进行了许多更改。 目前,当我使用eclipse as as ...在服务器上运行时,在tomcat服务器的新实例中启动应用程序时,收到以下错误消息:

SEVERE: Exception loading sessions from persistent storage  

服务器和应用程序随后可以成功启动,但是我想修复导致错误消息的所有内容。 谁能告诉我如何克服此错误消息?

堆栈跟踪不会列出应用程序中的任何文件,因此我不知道在应用程序代码中可以查找该位置的问题。 您可以查看github上的petclinic代码,以查看应用程序的结构,如果这有助于您了解应该在哪里找到问题的话。 这是堆栈跟踪:

INFO  EhCacheManagerFactoryBean - Initializing EhCache CacheManager
INFO  ContextLoader - Root WebApplicationContext: initialization completed in 4376 ms
Dec 16, 2013 2:51:56 PM org.apache.catalina.session.StandardManager doLoad
SEVERE: IOException while loading persisted sessions: java.io.EOFException  
java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    at org.apache.catalina.util.CustomObjectInputStream.<init>(CustomObjectInputStream.java:58)
    at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:246)
    at org.apache.catalina.session.StandardManager.load(StandardManager.java:204)
    at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:491)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Dec 16, 2013 2:51:56 PM org.apache.catalina.session.StandardManager startInternal
SEVERE: Exception loading sessions from persistent storage  
java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    at org.apache.catalina.util.CustomObjectInputStream.<init>(CustomObjectInputStream.java:58)
    at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:246)
    at org.apache.catalina.session.StandardManager.load(StandardManager.java:204)
    at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:491)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Dec 16, 2013 2:51:56 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'petclinic'  
trans by 2020-08-09T02:04:59Z

java-如何为当前项目工作在IntelliJ IDEA 14中配置注释处理?

该项目的结构为:

  • 父项目
    • 一个项目(Spring)在pom.xml中具有项目B的依赖项
    • B项目(Spring MVC)在pom.xml中具有项目A的依赖项

在Tomcat 7中启动项目B后,出现错误:

错误:java:模块周期不支持注释处理。 请确保注释处理中不包含周期[A,B]中的所有模块

如何避免这个问题?

我使用Java 8,Tomcat 7和想法14。

trans by 2020-08-07T04:16:09Z

java-自动装配失败:不是托管类型

我的文凭项目有一个大问题,如果你们能帮助我,我将非常高兴!我做了一个Maven多模块项目,有3个“核心项目”

  • NaviCleanServer :(父母)
  • NaviCleanServer:包含我所有实体的域模型,并且NaviCleanServer需要的接口einRemoteDienst30003000766766484190212和NaviCleanClient
  • NaviCleanServer:包含GUI和与之的Hessian连接einRemoteDienst
  • NaviCleanServer:这是我的存储库,与数据库的连接和接口的实现einRemoteDienstNaviCleanServerNaviCleanClient在Maven中具有NaviCleanDomain依赖关系。

现在,每次尝试在Tomcat上启动服务器时,都会出现以下错误:

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transaktionsRepository': 
Injection of persistence dependencies failed; 
nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: 
Error loading class [at.naviclean.service.impl.MeinRemoteDienstImpl] for bean with name 'meinRemoteDienstImpl' defined in file [C:\Users\Fredy\Documents\workspace-sts-3.1.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\NaviCleanServer\WEB-INF\classes\at\naviclean\service\impl\MeinRemoteDienstImpl.class]: 
problem with class file or dependent class; 
nested exception is java.lang.NoClassDefFoundError: at/naviclean/service/MeinRemoteDienst
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
    ……………….

模型库:

package at.naviclean.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@SuppressWarnings("serial")
@MappedSuperclass
public class ModelBase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Version
    @Column(name = "ts")
    private Date timestamp;

    public Long getId() {
        return id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

}

收银台:

package at.naviclean.domain;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Kassa extends ModelBase {

    @Column(name = "name", unique = true)
    private String name;

    @Column(name = "geld")
    private int geld;

    public Kassa(String name, int geld) {
        this.name = name;
        this.geld = geld;
    }

    public Kassa() {
    }

    public String getName() {
        return name;
    }

    public int getGeld() {
        return geld;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGeld(int geld) {
        this.geld = geld;
    }

}

主要远程:

package at.naviclean.service;

import at.naviclean.domain.Kassa;

public interface MeinRemoteDienst {

    int getKassaCount(int plus);

    String getNameFromKassa(int id);

    Kassa findById(int id);
}

基本资料库

package at.naviclean.repositories;

import org.springframework.data.jpa.repository.JpaRepository;

import at.naviclean.domain.ModelBase;

public interface BaseRepository<T extends ModelBase> extends
        JpaRepository<T, Long> {
    T findById(long id);

}

Kassa存储库:

package at.naviclean.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import at.naviclean.domain.Kassa;

public interface KassaRepository extends BaseRepository<Kassa> {
    List<Kassa> findByGeld(int geld);

    Kassa findByName(String name);

    @Query("select k from Kassa k where k.geld = ?1")
    Kassa findByGeld1(int geld);
}

Main Remotenji schi mpl:

package at.naviclean.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import at.naviclean.domain.Kassa;
import at.naviclean.repositories.KassaRepository;
import at.naviclean.service.MeinRemoteDienst;

@Service
public class MeinRemoteDienstImpl implements MeinRemoteDienst {

    @Autowired(required = true)
    public KassaRepository kassaR;

    public int getKassaCount(int plus) {
        return 2;
    }


    public String getNameFromKassa(int id) {
        return kassaR.findById(id + 0l).getName();
    }

    @Override
    public Kassa findById(int id) {
        return = kassaR.findById(id + 0l);
    }

}

application-context.xml:

<?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:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <import resource="infrastructures.xml" />

    <jpa:repositories base-package="at.naviclean.repositories">
        <repository:exclude-filter type="regex"
            expression="at.naviclean.repositories.BaseRepository" />
    </jpa:repositories>

    <context:component-scan base-package="at.naviclean.service.impl" />

</beans>

Infrastructures.xml:

<?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:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                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">



        <bean id="entityManagerFactory"
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="dataSource" />
                <property name="jpaVendorAdapter">
                        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                <property name="showSql" value="true" />
                                <property name="generateDdl" value="true" />
                                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
                        </bean>
                </property>
        </bean>

        <bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/kassatest" />
                <property name="username" value="root" />
                <property name="password" value="" />
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>


        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

</beans>

servlet-context.xml:

<?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:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



<import resource="../root-context.xml" />
    <bean id="idMeinRemoteDienst" class="at.naviclean.service.impl.MeinRemoteDienstImpl" />
    <bean name="/MeinRemoteDienstHessian"
        class="org.springframework.remoting.caucho.HessianServiceExporter"
        p:serviceInterface="at.naviclean.service.MeinRemoteDienst"
        p:service-ref="idMeinRemoteDienst" />

</beans>

root-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="classpath:META-INF/spring/application-context.xml" />

</beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>

</web-app>

这是我已经尝试过的:1.我写了这个测试“变成红色”:

package at.spengergasse.kassa;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import at.naviclean.domain.Kassa;
import at.naviclean.repositories.KassaRepository;

@ContextConfiguration("classpath:META-INF/spring/application-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class KassaTest {

    @Autowired(required = true)
    private KassaRepository kassaR;

    @Before
    public void setUp() throws Exception {

    }

    @Test
    public void findByIdTest() {
        Kassa k = kassaR.findById(2);

        assertThat(k, is(not(nullValue())));
    }

    @Test
    public void findByGeld() {
        Kassa k = kassaR.findByGeld1(1200);

        assertThat(k, is(not(nullValue())));
    }

    @Test
    public void test() {
        Kassa vorher = new Kassa("ssf", 222);
        kassaR.save(vorher);
        Kassa nachher = kassaR.findById(vorher.getId());
        kassaR.delete(nachher);
        assertThat(vorher.getId(), is(equalTo(nachher.getId())));
    }

}

错误:

ERROR: org.springframework.test.context.TestContextManager - 
Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@41e22632] to prepare test instance [at.spengergasse.kassa.KassaTest@6639be68]
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


Caused by: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'meinRemoteDienstImpl': 
**Injection of autowired dependencies failed**; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: public at.naviclean.repositories.KassaRepository at.naviclean.service.impl.MeinRemoteDienstImpl.kassaR; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'kassaRepository': FactoryBean threw exception on object creation; 
nested exception is java.lang.IllegalArgumentException: **Not an managed type: class at.naviclean.domain.Kassa**
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    ………..

2.我在域模型的persistence.xml中手动插入了一个存储库。 结果是“绿色”测试,但我仍然无法启动服务器...

在此先感谢!!! 我无法想象没有你会是什么:)

trans by 2020-08-07T03:34:23Z

java-在Spring Data JPA中处理实体继承的最佳方法

我有三个具有以下层次结构的JPA实体类ARespositoryRepositoryARepository

    A
    |
+---+---+
|       |
C       B

那是:

@Entity
@Inheritance
public abstract class A { /* ... */ }

@Entity
public class B extends A { /* ... */ }

@Entity
public class C extends A { /* ... */ }

使用Spring Data JPA,为此类实体编写存储库类的最佳方法是什么?

我知道我可以写这些:

public interface ARespository extends CrudRepository<A, Long> { }

public interface BRespository extends CrudRepository<B, Long> { }

public interface CRespository extends CrudRepository<C, Long> { }

但如果在类别ARespository中有一个字段Repository,我在ARepository中添加了此方法:

public A findByName(String name);

我还要在其他两个存储库中编写这种方法,这有点烦人。是否有更好的方法来处理这种情况?

我想说的另一点是ARespository应该是只读存储库(即扩展3000180124835906906561类),而其他两个存储库应该公开所有CRUD操作。

让我知道可能的解决方案。

trans by 2020-08-07T01:06:46Z

java-两个微服务之间的通信

我正在创建一个具有微服务架构的项目。 我创建了两个微服务。

其中一个用于产品实体,另一个用于票据实体。 它们具有自己的端点,并且与网关连接在一起(我正在使用jhipster微服务体系结构)。

清单应访问产品列表。 我想知道如何在这两个毫秒之间进行通信。 我想到三种方法:

  1. 从bill-ms发送请求到队列-像RabbitMQ一样,从product-ms获取具有这些ID的这些产品(我不知道这是什么瓶颈)

  2. 向产品服务的网关发送请求并从那里获取产品(我担心延迟,因为它们之间的数据量很大,因此我不会直接接触数据库,所以我总是依赖网关)

  3. 我可以在Bill-ms中复制存储库,服务和实体(这是一种丑陋的方式,我认为这违反了ms-architecture的规则,维护起来非常困难)

如果您有其他方法,非常感谢您与我分享。

编辑

  1. 现在我知道了瓶颈所在:假设有3个bill-ms实例,rabbitMQ如何决定响应哪个实例? 或者我该如何对功能区说“给我Bill-ms的免费实例以订阅RabbitMQ的请求”以实现负载平衡。
trans by 2020-08-07T00:56:03Z

java-在Spring MVC应用程序中,服务层使用什么命名约定?

我一直在为Spring应用程序中的服务层找出一个好的命名约定。 对于服务层中的每个类,我首先编写它应实现的接口,然后再编写实际的类。 因此,例如,我有以下界面:

public interface UserAccountManager{
   public void registerUser(UserAccount newUserAccount);
   public void resetPassword(UserAccount userAccount);
...
}

然后是实现类...

这里让我感到困扰的是UserAccountManager是实现类的好名字,因此我被迫给它一个愚蠢的名字,例如SimpleUserAccountManager或UserAccountDbManager。到目前为止,您使用了哪些约定? 将实现类放在不同的包中并为它们提供与接口相同的名称是个好主意吗?另外,对于使用以Manager结尾的名称而不是以Service结尾的名称,您有何想法?

trans by 2020-08-06T20:08:10Z

java-如何获取Spring 4.1使用的Jackson ObjectMapper?

Spring 4.1实例化了Jackson ObjectMapper实例。 我有理由想要将该实例@Autowire放入我的一个控制器中:控制器使用Jackson对其自身进行一些较小的JSON解析,但是它使用的ObjectMapper应该是Spring本身使用的一个实例。 我该如何去实现?

请注意,我并不是在问如何自定义配置Spring使用的ObjectMapper。 我对默认设置感到满意。 我只想获取Spring所使用的实例,以便可以在自己的代码中重用现有实例。

trans by 2020-08-06T12:46:07Z

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 下一页 共36页