Tag: annotations

使用Java配置和Spring Security 3.2的安全方法注释

我在使用@EnableGlobalMethodSecurity控制的方法级别注释设置应用程序时遇到一些问题我正在使用Servlet 3.0样式初始化 public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer { public SecurityWebApplicationInitializer() { super(MultiSecurityConfig.class); } } 我尝试了两种不同的方法来初始化AuthenticationManager和它们自己的问题。 请注意, 不使用@EnableGlobalMethodSecurity导致服务器启动成功,并且所有表单安全性都按预期执行。 当我在@EnableGlobalMethodSecurity添加@EnableGlobalMethodSecurity和@PreAuthorize(“hasRole(‘ROLE_USER’)”)注释时,我的问题出现了。 我试图独立设置基于表单和基于api的安全性。 基于注释的方法仅需要用于api安全性。 一种配置如下。 @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled=true) public class MultiSecurityConfig { @Configuration @Order(1) public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { http.antMatcher(“/api/**”).httpBasic(); } protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser(“user”).password(“password”).roles(“USER”).and() […]

如何在客户端使用JAXB注释进行GWT?

我想在我的类中使用JaxB注释,如下所示: @XmlRootElement public class ItemExtension implements Serializable { 但当我把它放在客户端时,GWT抱怨。 [ERROR] Line 4: The import javax.xml.bind cannot be resolved [ERROR] Line 14: XmlRootElement cannot be resolved to a type 有解决方法还是我做错了什么?

注释处理器,生成编译器错误

我正在尝试创建一个自定义注释,例如,确保字段或方法既是public也是final ,如果字段或方法不是public和final ,则会产生编译时错误,如下例所示: // Compiles @PublicFinal public final int var = 2; // Compiles @PublicFinal public final void myMethod {} // Compile time error @PublicFinal private final int fail = 2; 到目前为止,我已经制作了两个自定义注释界面: import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Documented @Retention(RetentionPolicy.SOURCE) @Target({ElementType.METHOD, ElementType.FIELD}) public @interface PublicFinal { } 和Processor : import javax.annotation.processing.AbstractProcessor; […]

在Spring 3中组织类进行组件扫描的智能方法是什么?

我已经开始使用Spring 3开发一个新项目了,我正在使用注释。 我喜欢我可以连接我的类来注入依赖项,但我知道context:component-scan是一个不好的做法context:component-scan从基础包开始。 我正在使用DispatcherServlet ,它有自己的xml配置文件。 这也是一个context:component-scan 。 当我第一次开始学习Spring时,我的组件扫描中有重叠,并且多次创建了bean。 我想避免这种情况。 组织我的包或组件扫描以覆盖所有bean而不重复的好方法是什么? 目前我有这样的包: my.package.controller my.package.dao my.package.entity my.package.service my.package.util 如果我在所有这些包中都有bean,那么似乎最简单的方法就是将放入applicationContext.xml并且完成它。 扫描调度程序的xml中的my.package.controller和my.package.controller中的其余部分(不包括my.package.controller)会更好吗? 或者我应该将所有注释的课程安排在一个区域,还有其他一些安排在另一个区域? 就像是: my.package.spring.controller my.package.spring.dao my.package.spring.entity my.package.spring.service my.package.spring.util my.package.notannotated my.package.notannotated2 我正在使用@Autowired向大多数(如果不是全部)类添加日志记录,所以我不知道我将有任何不会被注释的类。 我讨厌陷入配置…我宁愿被困在代码中,所以如果有人可以提供任何提示,我会很乐意欢迎他们。 谢谢!

如何在Spring中重启死锁/锁定超时的事务?

在使用Spring(特别是Spring推荐的方法:声明式事务)时,在死锁或锁定超时exception时实现事务重启的最佳实践是什么? 谢谢, 阿萨夫

在切入点内获取带注释的参数

我有两个注释@LookAtThisMethod和@LookAtThisParameter ,如果我使用@LookAtThisMethod对方法进行@LookAtThisMethod ,我怎样才能提取用@LookAtThisParameter注释的所述方法的参数? 例如: @Aspect public class LookAdvisor { @Pointcut(“@annotation(lookAtThisMethod)”) public void lookAtThisMethodPointcut(LookAtThisMethod lookAtThisMethod){} @Around(“lookAtThisMethodPointcut(lookAtThisMethod)”) public void lookAtThisMethod(ProceedingJoinPoint joinPoint, LookAtThisMethod lookAtThisMethod) throws Throwable { for(Object argument : joinPoint.getArgs()) { //I can get the parameter values here } //I can get the method signature with: joinPoint.getSignature.toString(); //How do I get which parameters are annotated with @LookAtThisParameter? […]

从Java Annotation Processor访问源代码

我试图从Java Annotation Processor中访问类型的实际原始源代码。 这有可能吗? 谢谢!

BeanNotOfRequiredTypeException

我还是Spring MVC的新手,在构建我的测试项目时,我从Tomcat日志中收到了这条消息: SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘divisionController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘adminService’ must be of type [employee.service.impl.AdminServiceImpl], but was actually of type [$Proxy52] at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) … […]

如何使用Hibernate获取两个字段的唯一键?

我有一个实体类的两个字段,我不希望它们是唯一的,而是用作一个键的复合字段,它必须是唯一的。 例如,我有两个字段(名称和版本),对于其他记录可以是相同的,但它们必须是唯一的。 使用Hibernate(带注释)的最佳方法是什么? 我正在使用Hibernate Validator用于其他字段,但我不确定如何使用它来validation两个字段一起组成一个唯一键。 我正在使用一个通用的实体类,它具有一个idgenerics类型,可以替换为复合键类,但我还没有让它工作得很好。

使用java注释注入logger依赖项

我使用带有aspect-j注释支持的@Loggable来允许@Loggable注释。 这允许基于配置自动登录类。 我想知道我是否可以以某种方式使用此注释将slf4j Logger变量暴露给类以供直接使用,这样我就不必对以下内容执行某些操作: Logger logger = LoggerFactory.getLogger(MyClass.class); 如果上面因为注释而隐式可用,那将是很好的,我可以去做logger.debug(“…”); 没有声明。 我不确定这是否可行。