虽然这个问题多次询问,但我已经使用了所有的建议,但我仍然遇到了这个错误.
User.java是
@Entity
@Table(name = "USER")
public class User implements UserDetails, Serializable {
private static final long serialVersionUID = 2L;
@Id
@Column(name = "USER_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "USERNAME")
private String username;
@Column(name = "PASSWORD")
private String password;
@Column(name = "NAME")
private String name;
@Column(name = "EMAIL")
private String email;
@Column(name = "LOCKED")
private boolean locked;
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@ElementCollection(targetClass=Role.class)
@Column(name = "ROLE_ID")
private Set<Role> roles;
@Override
public GrantedAuthority[] getAuthorities() {
List<GrantedAuthorityImpl> list = new …Run Code Online (Sandbox Code Playgroud) 任何人都可以向我解释注释如何在java内部工作?
我知道如何通过在java中使用java.lang.annotation库来创建自定义注释.但我仍然没有得到它在内部的工作方式,例如@Override注释.
如果有人能详细解释,我将非常感激.
我正在使用Spring 3.1并使用@Configuration和@ComponentScan属性引导应用程序.
实际开始是完成的
new AnnotationConfigApplicationContext(MyRootConfigurationClass.class);
Run Code Online (Sandbox Code Playgroud)
此Configuration类使用注释
@Configuration
@ComponentScan("com.my.package")
public class MyRootConfigurationClass
Run Code Online (Sandbox Code Playgroud)
这很好用.但是我想更具体地说明我扫描的软件包,所以我试过了.
@Configuration
@ComponentScan("com.my.package.first,com.my.package.second")
public class MyRootConfigurationClass
Run Code Online (Sandbox Code Playgroud)
但是,这会失败,并告诉我无法找到使用@Component注释指定的组件.
做我正在做的事情的正确方法是什么?
谢谢
我通过使用Spring和Hibernate为服务创建实体,服务和JUnit测试来启动我的项目.所有这一切都很棒.然后我添加了spring-mvc来使用许多不同的分步教程来创建这个Web应用程序,但是当我尝试使用@Autowired注释创建Controller时,我在部署期间遇到来自Glassfish的错误.我想由于某些原因Spring没有看到我的服务,但经过多次尝试后我仍然无法处理它.
服务测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/beans.xml"})
Run Code Online (Sandbox Code Playgroud)
和
@Autowired
MailManager mailManager;
Run Code Online (Sandbox Code Playgroud)
工作正常.
没有@Autowired的控制器,我可以毫无困难地在Web浏览器中打开我的项目.
/src/main/resources/beans.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<context:property-placeholder location="jdbc.properties" />
<context:component-scan base-package="pl.com.radzikowski.webmail">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!--<context:component-scan base-package="pl.com.radzikowski.webmail.service" />-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- Persistance Unit Manager for persistance options managing …Run Code Online (Sandbox Code Playgroud) 目前,有两种方法可以将代码标记为java中的depreacted.
通过JavaDoc
/**
* @deprecated
*/
Run Code Online (Sandbox Code Playgroud)
或者作为注释:
@Deprecated
Run Code Online (Sandbox Code Playgroud)
这是我的问题 - 当使用Eclipse将方法标记为已弃用时,我发现声明两者都有点太多了.我真的只想用其中一个.
但是,使用注释会给编译器提供实际有用的附加信息吗?
但是只使用注释,我无法说明为什么该方法被弃用 - 我只能用JavaDoc做到这一点,并且弃用方法而不指出为什么不好.
那么,我可以只使用其中一个吗?或者我应该真的学会指定两者?
public class NaiveAlien extends Alien
{
@Override
public void harvest(){}
}
Run Code Online (Sandbox Code Playgroud)
我试图理解我朋友的代码,但我没有在代码中获得语法@Override.这是做什么的,为什么我们需要编码?谢谢.
我读了javadoc @EnableWebMvc.
但我不明白这个注释是什么意思?
你能清楚地解释它吗?
为什么我会收到错误"属性值必须保持不变".是不是空不变???
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SomeInterface {
Class<? extends Foo> bar() default null;// this doesn't compile
}
Run Code Online (Sandbox Code Playgroud) 我正在使用我的uuid如下:
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
private String uuid;
Run Code Online (Sandbox Code Playgroud)
但我得到了一个聪明的Hibernate警告:
使用org.hibernate.id.UUIDHexGenerator,它不生成符合IETF RFC 4122的UUID值; 考虑使用org.hibernate.id.UUIDGenerator
所以我想切换到org.hibernate.id.UUIDGenerator,现在我的问题是如何告诉Hibernate的生成器.我看到有人把它用作"hibernate-uuid" - 所以这就是我尝试过的,但结果是否定的:
@Id
@GeneratedValue(generator = "hibernate-uuid")
@GenericGenerator(name = "hibernate-uuid", strategy = "hibernate-uuid")
@Column(name = "uuid", unique = true)
private String uuid;
Run Code Online (Sandbox Code Playgroud) 我一直试图找到一个JPA Criteria API教程但是没有取得多大成功.你知道任何初学者吗?我想在Java5/Maven应用程序中开始使用它来构建复杂的搜索查询.
annotations ×10
java ×10
spring ×3
hibernate ×2
jpa ×2
spring-mvc ×2
autowired ×1
default ×1
deprecated ×1
javadoc ×1
jpa-2.0 ×1
overriding ×1
uuid ×1