Tag: spring

使用AspectJ的Spring MVC

我有一个工作的spring mvc项目。 我想使用AspectJ通过我的控制器记录每个请求。 相关代码: 控制器:(在hu.freetime.controller包中) @Controller @RequestMapping(“/”) public class BaseControllerImpl { @RequestMapping(method = RequestMethod.GET) public String index(Model model) { return “index”; } } 方面: @Aspect public class ControllerAspectImpl { Logger logger = LoggerFactory.getLogger(ControllerAspectImpl.class); @Pointcut(“execution(public * hu.freetime.controller.BaseControllerImpl.*(..))”) public void logController() { } @Around(“logController()”) public void log(final ProceedingJoinPoint pjp) { MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method […]

订阅Spring Metrics频道

因此,根据Spring的文档,它将在REST端点和消息通道上发布指标。 REST端点工作正常,因为我得到了预期的结果。 但是,我想处理指标中的每个更改。 因此它表示默认情况下会将消息发布到名为“metricsChannel”的频道 我试图创建以下类来听这个频道,但它似乎没有激发。 其他所有内容都保留了Spring Boot应用程序的默认值。 package services.core; import org.springframework.stereotype.Service; import org.springframework.integration.annotation.ServiceActivator; @Service public class MetricService { @ServiceActivator(inputChannel = “metricsChannel”) public void handleMessage(org.springframework.messaging.Message message) { System.out.println(“Message [” + message.toString() + “] is received”); } }

Spring MVC 3 localeChangeInterceptor

我想将Internationalization添加到我的Spring MVC应用程序中。 我知道这可能是一个复制问题,但我已经尝试了stackoverflow和谷歌的所有解决方案,但仍然无法正常工作。 我会详细解释一下。 这是 web.xml中 contextConfigLocation /WEB-INF/spring/root-context.xml 根的context.xml /WEB-INF/messages 我有messages_en.properties和messages_tr.properties文件。 它们工作正常,因为当我将defaultLocale更改为en或tr时,我从属性文件中获得了真正的标签。 但问题是,当我尝试使用浏览器时?lang=tr or ?lang=en没有任何变化。 谢谢你的关注!

对于预检,响应具有无效的HTTP状态代码401,用于oauth / token

我在spring boot中为CORS实现了Filter。代码如下: – @SpringBootApplication @Component public class Application implements Filter { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; response.setHeader(“Access-Control-Allow-Origin”, “*”); response.setHeader(“Access-Control-Allow-Credentials”, […]

使用@Transactional时,EntityManager.persist()不会插入数据

最近我将项目设置更改为使用Spring进行声明式事务处理。 或者至少我想。 当我调用persist ,不执行任何INSERT语句。 我为Spring ORM启用了TRACE日志级别,这就是我得到的: DEBUG JpaTransactionManager: Creating new transaction with name [albw.service.TransactionTestService.doServiceMethod]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ” DEBUG JpaTransactionManager: Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@28a7bd7a] for JPA transaction DEBUG BasicResourcePool: trace com.mchange.v2.resourcepool.BasicResourcePool@10ea443f [managed: 5, unused: 4, excluded: 0] (eg com.mchange.v2.c3p0.impl.NewPooledConnection@1ca37c6a) DEBUG JpaTransactionManager: Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@55d4ee7e] TRACE TransactionSynchronizationManager: Bound value [org.springframework.jdbc.datasource.ConnectionHolder@e75be38] for key [com.mchange.v2.c3p0.ComboPooledDataSource [ […]

将Spring-wired库与机器人框架结合使用

我有一个精心设计的Spring bean设置用于集成测试。 现在,我正在研究编写一个Robot库,以便将我的测试数据创建/行为执行/断言方法暴露给Robot测试。 但是,我从Robot Framework用户指南中了解到,Robot只能通过调用构造函数来实例化库类。 这是一个无赖,因为我宁愿让我的实例由Spring管理。 理想情况下,我希望能够为Robot提供应用程序上下文的路径和库的bean名称。 如果做不到这一点,我希望Robot能够调用静态工厂方法而不是构造函数,所以我不会被迫创建一个新实例。 我想到的一个解决方法是在静态初始化程序中创建Spring上下文,并通过从该上下文中提取bean来连接我的依赖项。 我原来的课看起来像: public class MyAwesomeTests { @Autowired private ThisHelper thisHelper; @Autowired private ThatHelper thatHelper; // implementations of test steps and such } 所以我会改变上面protected @Autowired字段,并创建一个静态初始化Spring上下文并定义一个Robot友好构造函数的子类: public class RobotFriendlyTests extends MyAwesomeTests { private static final ApplicationContext CONTEXT = new ClassPathXmlApplicationContext(…); public RobotFriendlyTests() { this.thisHelper = (ThisHelper) CONTEXT.getBean(“thisHelper”); this.thatHelper = […]

Spring 3..0.5 + hierbnate 3.6.6.final + jboss as 7数据库访问

我正在将我们的项目从spring 2.5.6,hibernate 3.3.2,jboss 4.2升级到Spring 3..0.5 + hierbnate 3.6.6.final + jboss as 7 。 那里有很多问题,我决定写一个简单的项目,并在jboss as7(使用Spring 3..0.5 + hierbnate 3.6.6.final)开始时将其删除。 该项目非常简单:DAO类将访问MYSQL数据库。 但是当它的entityManager尝试访问数据库时,应用程序失败,抛出“抛出exception:org.hibernate.MappingException:未知实体”。 以下是我的项目: 我的web控制器类: package com.yan.testing.web.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.yan.testing.jpa.dao.IYanDao; import com.yan.testing.jpa.entity.Yan; @Controller public class WebController { @Autowired IYanDao yanDao; @RequestMapping(“sayHello.do”) public String SayHello(){ Yan yan = yanDao.findById(1L); System.out.println(yan.getName()); return “sayHello”; } […]

如何使用websockets从mysql获取实时通知更新?

从几天开始,我一直在搜索社交网络或Q / A网站如何获得实时通知。 我开始了解订阅者 – 发布者模式。 我开始知道使用WebSockets获取实时更新。 Websocket发布端点,客户端订阅该端点,并不断获取任何更改的更新。 但我从网上得到的例子都是聊天应用程序。 但我的要求是从MySQL DB获取实时通知。 所以我的想法很少 我是否正在使用WebSockets来满足正确的要求? 或者我的要求还有其他一些有效的方法吗? 如果这对我来说是有效的方式,我认为解决这个问题的模式是:WebSocket将连接到MySql并始终查找更改。 它还发布了我的客户端将始终寻找的端点。 提交给Mysql的任何更改都将反映在WebSocket中并导致客户端应用程序。 如果我的模式是正确的,我不知道如何将WebSocket连接到Mysql。 任何帮助/指导都非常感谢。 更新 : 经过一些网络搜索: 1.由于我为我的网站创建了Rest Webservices,AJAX是实现通知function而不是WebSockets的更好方法吗? 2. WebSockets是否比实现Rest端点的AJAX调用更复杂(因为两者的目的相同,是为了获取通知)?

dependency injection如何工作?

我正在阅读Pro Spring 2.5书,我对dependency injection如何工作有疑问。 我理解BeanFactory并进行依赖查找。 现在我读到dependency injection,我有一些问题。 根据我的理解,您希望将查找限制到最小,例如查找对象以启动应用程序。 然后dependency injection将处理其余的事情。 但是我不明白这是有效的。 假设您有一个beanfactory,您将获得一个启动整个应用程序的MyApplication实例。 其余对象使用dependency injection来获取其协作者。 beanfactory维护它管理的bean列表,但这个工厂不仅仅在应用程序的main方法中可用吗? 如果beanfactory还管理其包含bean的范围,我不明白这是怎么做的。 豆瓣在某种程度上是全球性的吗?

StackOverflowError试图在Spring WebSecurityConfigurerAdapter中公开AuthenticationManager

我试图通过扩展WebSecurityConfigurerAdapter来创建一个Spring Security配置,基本上是这样的: @EnableWebSecurity @Configuration public class StackOverflowSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(myUsernamePasswordProvider()); auth.authenticationProvider(mySecurityTokenProvider()); super.configure(auth); } @Override @Bean public AuthenticationManager authenticationManager() throws Exception { return super.authenticationManagerBean(); } @Bean public MyPreAuthenticatedProcessingFilter myAuthenticationFilter() throws Exception { MyPreAuthenticatedProcessingFilter myAuthenticationFilter = new MyPreAuthenticatedProcessingFilter(); myAuthenticationFilter.setAuthenticationManager(authenticationManager()); return myAuthenticationFilter; } } 我看到了这个: SEVERE: Servlet.service() for servlet […]