Tag: spring

如何在Spring中的RESTful Web应用程序中进行身份validation(登录/注销)?

我想通过身份validation http://myhost/login?user=…&password=… 并注销 http://myhost/logout 我正在使用Gradle,Spring Boot和Java配置,因此没有web.xml,没有上下文配置,没有Web表单等等。 在多页和多文件样本上无法摆脱谷歌噪音……

从应用程序的其他层发送STOMP消息

我正在使用带有RabbitMQ代理的集群tomcat环境中使用Spring Websockets构建应用程序。 我有一个API模块需要注册端点来监听。 我按照正常的例子提出了这个配置: @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void configureMessageBroker(final MessageBrokerRegistry config) { config.enableStompBrokerRelay(“/topic/”) .setRelayHost(“localhost”) .setRelayPort(61613) .setClientLogin(“guest”) .setClientPasscode(“guest”); } @Override public void registerStompEndpoints(final StompEndpointRegistry registry) { registry.addEndpoint(“/updates”) .setAllowedOrigins(“*”) .withSockJS(); } } 虽然这有效,但它并没有解决我的问题,因为看起来WebSocket和中继配置都捆绑在API模块中,因此其他层无法重用代理。 我需要在服务层发生stomp消息代理中继配置,以便我们的应用程序的其他模块可以将消息推送到RabbitMQ中的主题,然后转向并通知API模块更新所有打开的websockets。 下面是我们的应用程序中相关层的示例图以及我要完成的任务。 我需要允许模块“Cron Message Sender”通过我们的其他API模块将消息推送给订阅消息主题的每个人。

在多模块Maven项目中注入自动assembly字段失败 – NoSuchBeanDefinitionException

我在Stackoverflow和其他网站上阅读了很多关于这个问题的post,但没有找到解决方案。 我有我的Maven模块的以下结构,其中一个主要父pom声明了所有这些模块(我在这里简化了结构以便仅显示相关部分): Maven模块http://sofzh.miximages.com/java/fc0f91.png 基础和“A”模块依赖于base-api模块。 基本模块包含base-api模块中包含的接口的实现。 我在“base-api”模块中有一个接口IFoo。 接口IFoo由“基础”模块中的类Foo实现。 类Foo用Spring的“@Service”注释注释。 我希望Foo服务在我的测试类中自动assembly,该测试类包含在模块“A”中: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class FooTest { @Autowired private IFoo foo; 我还为我的测试创建了一个上下文配置文件,其中包含以下行 IFoo和Foo都包含在xyz的子包中(在不同的maven模块中,如上所述)。 当我在Eclipse中运行测试(使用m2eclipse插件)时,它会正确传递。 但是,当我运行maven构建(mvn clean install)时,会发生以下错误: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [xyzvIFoo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations {@org.springframework.beans.factory.annotation.Autowired(required=true)} 我究竟做错了什么?

使用@Configuration和@Controller注释一个类。 需要帮助重构

下面是我必须同时使用@Configuration和@Controller类,因为在整个应用程序中应该只有一个Thymeleaf实例,否则我会得到例外。 我的其他类用@RequestScope注释,所以我不能使用单例作用域bean。 所以我有一个配置和控制器的混合来获得结果,但我觉得这是一个不好的做法。 我将不胜感激任何帮助重构代码并删除不良做法。 UPDATE 我使用的是spring-boot 1.5.14 。 我使用以下方法处理模板并将处理后的模板保持为字符串。 @Controller @Configuration @EnableWebMvc @ApplicationScope public class MyThymeleafConfig { @GetMapping(“/view-template”) @ResponseBody public void viewTemplates() { Context context = new Context(); context.setVariable(“mydata”, “this is it”); String html = templateEngine().process(“templates/view-to-process.html”, context); System.out.println(html); } /* configuration for thymeleaf and template processing */ @Bean public SpringTemplateEngine templateEngine() { SpringTemplateEngine templateEngine = […]

如何在Spring XML文件中使用DOCTYPE

大多数时候我们都没有在Spring中声明DOCTYPE 。 但我想在我的XML上下文文件中声明一个DOCTYPE,以便我可以在我的xml文件中使用ENTITY 。 例如: <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" [ %crmHome;] > 这给出了很多错误,比如… – Attribute “xmlns” must be declared for element type “beans”. – Attribute “xmlns:xsi” must be declared for element type “beans”. etc….. 实现这个目标的方法是什么?

如何在Spring Boot中实现Oracle AQ队列?

我已经了解了如何使用AQ(Streams?)包创建Oracle数据库。 我还在Oracle中创建了一些队列(手动)。 (使用PL / SQL和SQL)。 但是,我很难从Spring建立正确的连接。 以下工作(使用oracle.AQ java包): private final String aqUrl = “jdbc:oracle:thin:@localhost:1521:orcl”; private final String aqUser = “queue_mut”; private final String aqPassword = “******”; private final String aqSchema = “queue_mut”; private final String aqTable = “aq_table1”; private final String aqQueue = “aq_queue1”; @Test public void testManualAQ() throws ClassNotFoundException, SQLException, AQException { Class.forName(“oracle.jdbc.driver.OracleDriver”); Connection […]

Spring MVC default-servlet-handler配置阻塞JSTL视图

我有简单的Spring配置 /pages/ .jsp 我的控制器是 package com.osfg.test; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * @author athakur */ @Controller public class TestController { @RequestMapping(value=”/test”, method=RequestMethod.GET) public String welcome() { return “test”; } } 我的JSP是 OSFG Test Page Hello World! 此配置工作正常(虽然CSS没有应用)。 所以我补充道 到我的Spring配置,现在页面本身停止加载给404。 令人惊讶的是,一切正常(使用CSS)将遵循配置 直接渲染无控制器参与。

Spring JPA Hibernate:慢查询SELECT

我遇到了一个优化问题,我无法弄清楚为什么我的查询太慢了。 我的实体在这里: @Entity @Table(name = “CLIENT”) public class Client { private static final long serialVersionUID = 1L; @Id @Column(name = “CLIENT_ID”) @SequenceGenerator(name = “ID_GENERATOR”, sequenceName = “CLIENT_S”, allocationSize = 1, initialValue = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “ID_GENERATOR”) private Long id; @Column(name=”LOGIN”) private String login; @Column(name=”PASSWORD”) private String password; 和DAO @NoRepositoryBean public interface ClientDao […]

如何使用spring配置Async和Sync Event发布者

我试图使用spring事件实现一个事件框架。我开始知道spring事件框架的默认行为是sync。 但是在Spring上下文初始化期间,如果它找到一个id为applicationEventMulticaster的bean,它就会表现为Async。 现在我想在我的应用程序中同时拥有同步和异步事件发布者,因为某些事件需要同步发布。 我尝试使用SysncTaskExecutor配置同步事件多播器,但我找不到将其注入我的AsyncEventPublisher的applicationEventPublisher属性的方法。 我的spring配置文件如下 有人可以帮我从这里出去吗 ?

Spring boot:找不到javassist

我从弹簧启动开始,我正在尝试在内存DB中编写一个小型应用程序和H2。 当我试图运行我的应用程序时,我有java.lang.ClassNotFoundException:javassist.bytecode.ClassFile所以我猜测类路径上缺少javassit jar。 我在调试模式下启动了应用程序,并且类路径中存在javassist-3.18.1-GA.jar。 我当然错过了一些东西,但我无法弄清楚是什么。 这是我的POM文件的内容 org.springframework.boot spring-boot-starter-parent 1.3.1.BUILD-SNAPSHOT org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools true org.springframework.boot spring-boot-starter-data-jpa com.h2database h2 org.springframework.boot spring-boot-maven-plugin 1.8 spring-snapshots http://repo.spring.io/snapshot true spring-milestones http://repo.spring.io/milestone spring-snapshots http://repo.spring.io/snapshot spring-milestones http://repo.spring.io/milestone 这是我的应用程序主类 @Configuration @EnableAutoConfiguration @ComponentScan public class Application { public static void main(String[] args) throws Exception{ SpringApplication.run(Application.class, args); } } 这是堆栈跟踪 org.springframework.beans.factory.BeanCreationException: Error creating bean with […]